我有一份 Jenkins 工作。 这非常简单:从 git 拉取,然后运行构建。
构建只是一步:
批量执行窗口命令
在我的用例中,我需要运行一些 python 脚本。 有些会失败,有些则不会。
python a.py
python b.py
什么决定了构建的最终状态? 看来我可以通过以下方式编辑:
echo @STABLE > build.proprieties
但是如果用户没有指定STABLE/UNSTABLE状态是如何分配的呢? 如果 b.py 引发错误并失败会发生什么?
最佳答案
如果命令返回不为零的退出代码,Jenkins 会将管道解释为失败。
在内部,构建状态通过 currentBuild.currentResult
设置,它可以具有三个值:SUCCESS
、UNSTABLE
或 FAILURE
.
如果您想自己控制管道的失败/成功,您可以捕获异常/退出代码并手动设置 currentBuild.currentResult
的值。插件也使用此属性来更改管道的结果。
例如:
stage {
steps {
script {
try {
sh "exit 1" // will fail the pipeline
sh "exit 0" // would be marked as passed
currentBuild.currentResult = 'SUCCESS'
} catch (Exception e) {
currentBuild.currentResult = 'FAILURE'
// or currentBuild.currentResult = 'UNSTABLE'
}
}
}}
关于jenkins - 在 Jenkins 中设置构建状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59065164/