有没有办法使用"propagate = false"?在具有声明性语法的Jenkinsfile中直接用于阶段/步骤? [英] Is there a way to use "propagate=false" in a Jenkinsfile with declarative syntax directly for stage/step?

查看:40
本文介绍了有没有办法使用"propagate = false"?在具有声明性语法的Jenkinsfile中直接用于阶段/步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以按以下说明在构建作业上使用传播:

您可能已经猜到了,如果您希望它不稳定或其他原因,可以自由选择 buildResult stageResult .您甚至可以使构建失败并继续执行管道.

只需确保您的Jenkins是最新的,因为这是一个相当新的功能.

You can use propagate on a build job as described here:

https://jenkins.io/doc/pipeline/steps/pipeline-build-step/

So you can use something like this to prevent a failing step from failing the complete build:

build(job: 'example-job', propagate: false)

Is there a way to use this for a stage or a step? I know i can surround it with a try/catch and that does works almost as i want. It does ignore the failing the stage and resumes the rest of the build, but it does not display the stage as failed. For now i write all failing stages to a variable and output that on a later stage, but this is not ideal.

If i cant suppress propagation in a stage/step, is there maybe a way to use the build() call to do the same? Maybe if i move it to another pipeline and call that via build()?

Any help appreciated.

解决方案

With catchError you can prevent a failing step from failing the complete build:

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'
            }
        }
    }
}

In the example above, all stages will execute, the pipeline will be successful, but stage 2 will show as failed:

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.

Just make sure your Jenkins is up to date, since this is a fairly new feature.

这篇关于有没有办法使用"propagate = false"?在具有声明性语法的Jenkinsfile中直接用于阶段/步骤?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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