Continue Jenkins pipeline past failed stage

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

    It depends whether you are using declarative pipeline syntax or scripted pipeline syntax.

    declarative pipeline syntax:

    pipeline {
        agent any
        stages {
            stage('one') {
                steps {
                    sh 'exit 0'
                }
            }
            stage('two') {
                steps {
                    sh 'exit 1'   // failure
                }
            }
        }
        post {
            always {
                sh 'exit 0'
            }
        }
    }
    

    Post-condition blocks contain steps the same as the steps section.

    scripted pipeline syntax:

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

提交回复
热议问题