Is there a way to use "propagate=false" in a Jenkinsfile with declarative syntax directly for stage/step? Is there a way to use "propagate=false" in a Jenkinsfile with declarative syntax directly for stage/step? jenkins jenkins

Is there a way to use "propagate=false" in a Jenkinsfile with declarative syntax directly for stage/step?


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:

Pipeline Example

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.


There are currently lots of suggestions for the scripted syntax, but for the declarative syntax work is in progress to support this.

Track the progress of https://issues.jenkins-ci.org/browse/JENKINS-26522 which groups all of the pieces together to achieve this. It has some interesting bits already marked as 'Resolved' (meaning a code change was made), such as https://issues.jenkins-ci.org/browse/JENKINS-49764 ( "Allow define a custom status for pipeline stage"). Unfortunately, I cannot find references to any of the tickets involved in the Jenkins changelog which would make sense since the parent ticket is not yet finished.

Of interest might also be the following : https://issues.jenkins-ci.org/browse/JENKINS-45579 which was reopened due to an issue. The environment for this is : enter image description here

Admittedly, there are a confusing number of tickets tracking this work, but that is probably due to the fact that the functionality being implemented has a number of use-cases.

Another interesting ticket is "Individual Pipeline steps and stages/blocks should have Result statuses" , for which I was able to find a related PR: https://github.com/jenkinsci/workflow-api-plugin/pull/63


It is worth noting that the declarative pipeline was always designed as being opinionated and as such was not meant to support everything possible with the scripted syntax. For more complicated workflows and use-cases where it does not serve your needs, scripted syntax may be the only (and recommended?) option.

For needs such as the one you've stated, if enough noise is made, the declarative pipeline will probably be modified in due course to support it.