【发布时间】:2016-03-24 19:00:06
【问题描述】:
我正在使用 Jenkins PowerShell 插件来构建一个项目。
但是,我发现无论我在 Windows PowerShell 命令中输入什么内容,Jenkins 总是认为我的构建成功。
这是一个例子:
如您所见,asdf 不是合法命令。 Jenkins 应该在构建后给我FAILURE。
但是控制台输出给了我:
Started by user admin
Building in workspace C:\Users\Administrator\.jenkins\jobs\Test\workspace
[workspace] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\hudson2092642221832331776.ps1'"
The term 'asdf' 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 C:\Users\ADMINI~1\AppData\Local\Temp\hudson2092642221832331776.ps1:1 char:5
+ asdf <<<<
+ CategoryInfo : ObjectNotFound: (asdf:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Finished: SUCCESS
我认为PowerShell的执行结果应该取决于$lastexitcode。
这是 PowerShell 插件的错误吗?
【问题讨论】:
-
发生错误时,在您的 powershell 脚本中使用“exit x”,其中 x 是一个非零数。看看詹金斯是否认为它失败了。
-
是的,Jenkins 认为
exit 1失败。 -
然后更改您的脚本以在发生错误时以非零错误代码退出。如果您希望它仅依赖于 $lastexitcode,那么在脚本底部检查 $lastexitcode 并在适用时使用 exit 1。
-
最后,我在脚本末尾添加
exit $LastExitCode。
标签: powershell jenkins jenkins-plugins