Continue Jenkins pipeline past failed stage

前端 未结 8 1219
北荒
北荒 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:49

    I had the same concern. I was able to resolve it doing this.

    Second stage will show in red and be marked as failed while the rest of the stages will keep running. You can set a flag and at the end of the stages check the flag and inform the status of the whole build.

    node {
    
        def build_ok = true
    
        stage('one') {
            sh 'exit 0'
        }
    
        try{
            stage('two') {
                sh 'exit 1'   // failure
            }
        } catch(e) {
            build_ok = false
            echo e.toString()  
        }
    
        stage('three') {
            sh 'exit 0'
        }
    
        ....
    
        if(build_ok) {
            currentBuild.result = "SUCCESS"
        } else {
            currentBuild.result = "FAILURE"
        }
    }
    
    0 讨论(0)
  • 2020-12-13 12:51

    Use

    propagate: false

    flag to move to next stage when previous stage fails.

    example:

    stage('<stage-name>'){
        node('<node-name>'){
            build job: '<job-name>', propagate: false
        }
    }
    
    stage('<stage-name>'){
        node('<node-name>'){
            build job: '<job-name>'
        }
    }
    
    0 讨论(0)
提交回复
热议问题