我尝试使用file参数创建Jenkins参数化构建。
用户将选择带参数的构建,并提供带有项目列表的文本文档(每行一个)。
我想尝试在我的PowerShell脚本中阅读这个列表然后去做一些服务电话(我有点怀疑)。
我正在努力让我的PowerShell脚本读取已传入Jenkins的文件,这是我到目前为止所拥有的
$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},但要么他们没有工作,要么我没有正确理解它。非常感谢任何帮助。
由于
答案 0 :(得分:0)
是的,我找到了我错的地方......
在我的文件参数中,我没有设置文件位置(EG I' d留空),但我输入了' \ input.txt'我看得很低
Building in workspace C:\Users\jonec34\.jenkins\jobs\getParty\workspace
Copying file to \input.txt
[workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\jonec34\AppData\Local\Temp\hudson6216657038417634126.ps1'"
getting requests from file
0
2884430041011214
Array now has 1 items
9751297519392363
Array now has 2 items
lfsdkjgskdjflgsdjfg
Array now has 3 items
Finished: SUCCESS