在失败阶段继续 Jenkins 管道 [英] Continue Jenkins pipeline past failed stage

查看:58
本文介绍了在失败阶段继续 Jenkins 管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一系列执行快速检查的阶段.即使有失败,我也想全部执行.例如:

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:

  • Build #4 显示了通常发生的情况.作业 two 失败,因此 three 无法运行.
  • 我对 Build #6 进行了 Photoshop 处理,以展示我希望看到的内容.作业 two 失败并显示为这样,但 three 仍在运行.真正的 Jenkins 可能会将整个 Build #6 显示为略带红色,这当然没问题.
  • Build #4 shows what normally happens. Job two fails so three does not run.
  • I Photoshopped Build #6 to show what I would like to see. Job two fails and is displayed as such, but three 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:

正如您可能已经猜到的那样,您可以自由选择 buildResultstageResult,以防您希望它不稳定或其他任何情况.您甚至可以使构建失败并继续执行管道.

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(5 月2019 年 1 月 14 日)

这篇关于在失败阶段继续 Jenkins 管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆