我遇到了一個問題,即作爲持續集成過程的一部分運行電源外殼腳本任務,並且腳本未收到正確數量的參數。TFS電源外殼任務未將正確的參數數量傳遞給腳本
這是我正在
Param
(
[string]$directory_path,
[string]$website_name,
[string]$app_n,
[string]$takePhysicalPath
)
$ScriptBlockContent =
{
$dirPath = $args[0]
$websiteName = $args[1]
$appName = $args[2]
$takePhysicalPath = $args[3]
$physicalPath = $False
Write-Host "Param: directory_path: " $dirPath
Write-Host "Param website_name: " $websiteName
Write-Host "Param app_n: " $appName
Write-Host "Param takePhysicalPath: " $takePhysicalPath
Write-Host 'Parameter Count: ' $args.Count
if ([bool]::TryParse($takePhysicalPath, [ref]$physicalPath))
{
Write-Host 'Parsed: ' $takePhysicalPath ' -> ' $physicalPath
}
else
{
Write-Host 'Not Parsed'
}
Write-Host $dirPath
Write-Host $websiteName
Write-Host $appName
Write-Host $physicalPath
}
劇本,如果我在一個PowerShell功能運行腳本我正確地獲取價值
$directory_path = "C:\SolutionsContent"
$website_name = "websiteName"
$app_n = "Styles"
$takePhysicalPath = "true"
Invoke-Command -ScriptBlock $ScriptBlockContent -ArgumentList $directory_path, $website_name, $app_n, $takePhysicalPath
這是輸出
,我傳遞給腳本的參數有以下幾種
-directory_path "C:\SolutionsContent" -website_name "websiteName" -app_n "Styles" -takePhysicalPath "true"
變量$ takePhysicalPath是從來沒有過,下面是輸出
任何想法?
我做了一太,不幸的是我抄我的測試方法之一,但即使它不工作 – Heinrich
如果您更改了作業,會發生什麼情況。您正在使用'args',但您也可以使用'Parameter'塊定義參數。那麼,如果你把'$ dirPath = $ args [0]'改成'$ dirPath = $ directory_path'? – Moerwald
剛剛測試,仍然獲得相同數量的參數,3 – Heinrich