我有一个使用bat命令运行Powershell脚本的Jenkins管道,该脚本从Jenkinsfile中传递了一些文本。
我的Jenkinsfile中有参数:
daLogNames="Copy Verivo Deployables (data) to Application Directory"
使用该参数的powershell脚本称为:
bat "powershell -nologo ./getLogFile.ps1 ${SERENA_TOKEN} ${pipelineParams.daLogNames} %WORKSPACE%/${env.EV_DA_APPNAME}.json"
由于以下消息,Jenkins构建失败:
data : The term 'data' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:72
+ ./getLogFile.ps1 **** Copy Verivo Deployables (data)
to ...
+ ~~~~
+ CategoryInfo : ObjectNotFound: (data:String) [], CommandNotFoun
dException
+ FullyQualifiedErrorId : CommandNotFoundException
如何在不引发错误的情况下传递(数据)?任何建议将被认真考虑。
答案 0 :(得分:1)
此文本:daLogNames="Copy Verivo Deployables (data) to Application Directory"
被直接放在蝙蝠中,因此最终结果如下:
powershell -nologo ./getLogFile.ps1 SERENA_TOKEN Copy Verivo Deployables (data) to Application Directory c:/workspace/APPNAME.json
(data)
部分被作为表达式读取,就像您已经写过一样:
write-host 1 + 1 is (1+1)
评估()
中事物的位置。但是它找不到data
作为要运行的东西,并且会引发错误。
正如Mathias R. Jessen所评论的那样,解决方法是引用所有文本,以便将其作为单个字符串参数传递给您的PowerShell脚本,例如
bat "powershell -nologo ./getLogFile.ps1 ${SERENA_TOKEN} ""${pipelineParams.daLogNames}"" %WORKSPACE%/${env.EV_DA_APPNAME}.json"
或者也许:
bat "powershell -nologo ./getLogFile.ps1 ${SERENA_TOKEN} '${pipelineParams.daLogNames}' %WORKSPACE%/${env.EV_DA_APPNAME}.json"