Show a Jenkins pipeline stage as failed without failing the whole job

前端 未结 7 1069
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 02:26

Here\'s the code I\'m playing with

node {
    stage \'build\'
    echo \'build\'

    stage \'tests\'
    echo \'tests\'

    stage \'end-to-end-tests\'
             


        
7条回答
  •  余生分开走
    2020-12-01 03:08

    I recently tried to use vaza's answer Show a Jenkins pipeline stage as failed without failing the whole job as template for writing a function that excutes a job in an own stage named like the job name. Surprisingly it worked, but maybe some groovy experts have a look at it :)

    Here is how it looks like if one of the jobs is aborted:

    def BuildJob(projectName) {
        try {
           stage(projectName) {
             node {      
               def e2e = build job:projectName, propagate: false
               result = e2e.result
               if (result.equals("SUCCESS")) {
               } else {
                  error 'FAIL' //sh "exit 1" // this fails the stage
               }
             }
           }
        } catch (e) {
            currentBuild.result = 'UNSTABLE'
            result = "FAIL" // make sure other exceptions are recorded as failure too
        }
    }
    
    node {
        BuildJob('job1')
        BuildJob('job2')
    }
    

提交回复
热议问题