【发布时间】:2021-11-05 16:23:01
【问题描述】:
我的 Jenkins 管道中的一个阶段应设置为不稳定,具体取决于脚本在其步骤中的退出代码:2 应将阶段状态设置为不稳定,而 1 应将阶段结果设置为失败。
如何做到这一点?我检查了“catchError”,但它似乎没有区分失败状态,只提供一种捕获非 0 退出(1,2...)的方法。
pipeline {
agent any
parameters {
string(name: 'FOO', defaultValue: 'foo', description: 'My foo param')
string(name: 'BAR', defaultValue: 'bar', description: 'My bar param')
}
stages {
stage('First') {
steps {
// If "script.py" exit code is 2, set stage to unstable
// If "script.py" exit code is 1, set stage to failed
sh """
. ${WORKSPACE}/venv/bin/activate
python ${WORKSPACE}/script.py --foo ${FOO} --bar ${BAR}
deactivate
"""
}
}
}
stage('Second') {
steps {
echo('Second step')
}
}
}
}
【问题讨论】:
-
我的答案已根据您的要求更新/修复
标签: python-3.x jenkins jenkins-pipeline