这是我正在使用的代码
node {
stage 'build'
echo 'build'
stage 'tests'
echo 'tests'
stage 'end-to-end-tests'
def e2e = build job:'end-to-end-tests', propagate: false
result = e2e.result
if (result.equals("SUCCESS")) {
stage 'deploy'
build 'deploy'
} else {
?????? I want to just fail this stage
}
}
有没有办法让我将“端到端测试”阶段标记为失败,而不会使整个工作失败?传播 false 总是将阶段标记为 true,这不是我想要的,但传播 true 将作业标记为失败,这也是我不想要的。
最佳答案
即使使用声明式管道,这现在也是可能的:
pipeline {
agent any
stages {
stage('1') {
steps {
sh 'exit 0'
}
}
stage('2') {
steps {
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
sh "exit 1"
}
}
}
stage('3') {
steps {
sh 'exit 0'
}
}
}
}
在上面的示例中,所有阶段都将执行,管道将成功,但阶段 2 将显示为失败:
正如您可能已经猜到的,您可以自由选择 buildResult
和 stageResult
,以防您希望它不稳定或出现其他情况。您甚至可以使构建失败并继续执行管道。
只需确保您的 Jenkins 是最新的,因为这是一个相当新的功能。
关于jenkins - 将 Jenkins 管道阶段显示为失败,但不会导致整个作业失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36852310/