Continue Jenkins pipeline past failed stage

前端 未结 8 1270
北荒
北荒 2020-12-13 12:23

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 {
              


        
8条回答
  •  半阙折子戏
    2020-12-13 12:32

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

    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.

    EDIT: You need "Pipeline: Basic Steps" 2.16 (May 14, 2019)

提交回复
热议问题