继续让詹金斯管道过失败的阶段 [英] Continue Jenkins pipeline past failed stage
问题描述
我有一系列执行快速检查的阶段.即使有失败,我也想全部执行.例如:
I have a series of stages that perform quick checks. I want to perform them all, even if there are failures. For example:
stage('one') {
node {
sh 'exit 0'
}
}
stage('two') {
node {
sh 'exit 1' // failure
}
}
stage('three') {
node {
sh 'exit 0'
}
}
阶段two
失败,因此默认情况下不执行阶段three
.
Stage two
fails, so by default stage three
is not executed.
通常这是parallel
的工作,但是我想在舞台视图中显示它们.在下面的模型中:
Ordinarily this would be a job for parallel
, but I want to display them in the stage view. In the mock up below:
- 内部版本4显示了正常情况.作业
two
失败,因此three
无法运行. - 我用Photoshopped Build#6展示了我希望看到的内容.作业
two
失败并如此显示,但three
仍在运行.真正的Jenkins可能会显示整个Build 6略带红色,这当然可以.
- Build #4 shows what normally happens. Job
two
fails sothree
does not run. - I Photoshopped Build #6 to show what I would like to see. Job
two
fails and is displayed as such, butthree
still runs. The real Jenkins would probably display the entire Build #6 tinged slightly red, which is of course fine.
推荐答案
现在可以这样做.以下是声明性管道的示例,但是catchError
也适用于脚本化管道.
This is now possible. Below is an example of a declarative pipeline, but catchError
works for scripted pipelines as well.
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将显示为失败:
In the example above, all stages will execute, the pipeline will be successful, but stage 2 will show as failed:
您可能已经猜到了,可以自由选择buildResult
和stageResult
,以防它变得不稳定或其他任何情况.您甚至可以使构建失败并继续执行管道.
As you might have guessed, you can freely choose the buildResult
and stageResult
, in case you want it to be unstable or anything else. You can even fail the build and continue the execution of the pipeline.
只需确保您的Jenkins是最新的,因为这是一个相当新的功能.
Just make sure your Jenkins is up to date, since this is a fairly new feature.
编辑:您需要管道:基本步骤" 2.16( 2019年5月14日)
这篇关于继续让詹金斯管道过失败的阶段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!