0
我正在嘗試使用文件參數創建一個Jenkins參數化版本。Jenkins參數化版本 - 在powershell中讀取文件
用戶將選擇帶參數的構建,並將提供一個帶有項目列表(每行一個)的文本文檔。
我想嘗試閱讀我的PowerShell腳本中的這個列表,然後關閉並撥打一些服務電話(我有點疑惑)。
我和讓我的PowerShell腳本來讀取已穿入詹金斯文件掙扎,這裏是我迄今爲止
$ids = Import-Csv input.txt
$array = @()
Write-Host $array.Length
foreach($id in $ids){
Write-Host $id.id
$array += $id
Write-Host "Array now has" $array.Length "items"
}
我知道腳本運行正常,因爲我可以運行Powershell ISE並傳入csv/txt文件的絕對路徑。
作爲參考,input.txt中的內容是這樣的:
id
2884430041011214,
9751297519392363,
lfsdkjgskdjflgsdjfg
這裏有兩個輸出我得到
Powershell的ISE(如預期):
0
2884430041011214
Array now has 1 items
9751297519392363
Array now has 2 items
lfsdkjgskdjflgsdjfg
Array now has 3 items
詹金斯(不是我所希望的)
Started by user anonymous
Building in workspace C:\Users\jonec34\.jenkins\jobs\getParty\workspace
[workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\jonec34\AppData\Local\Temp\hudson4035619350462822370.ps1'"
Import-Csv : Could not find file 'C:\Users\jonec34\.jenkins\jobs\getParty\workspace\input.txt'.
At C:\Users\jonec34\AppData\Local\Temp\hudson4035619350462822370.ps1:1 char:8
+ $ids = Import-Csv input.txt
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Import-Csv], FileNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ImportCsvCommand
0
Finished: SUCCESS
任何人都可以告訴我我該如何做到這一點。我也嘗試在腳本的開頭放置Param($ file),並使用$ {WORKSPACE},但是它們不能正常工作,或者我沒有正確理解它。任何幫助不勝感激。
感謝