简体   繁体   中英

Jenkins: Single email summary report of pipeline jobs/stages?

Is there a common approach to sending an email notification for summarizing the underlying jenkins stsages and jobs?

Right now, we have a parent pipeline that calls other jobs or pipeline jobs within it. Each job is sending its own email right now and it's becoming too noisy.

So for example, if I have 2 stages, each with 2 parallel tasks/jobs. I want to send an email summary like:

Stage 1: FAIL (because taskA failed)

--firstTaskA: PASS

--firstTaskB: FAIL

Stage 2: PASS

--firstTaskA: PASS

--firstTaskB: PASS

Example pipeline:

stage("Stage 1") {
    steps {
        parallel (
            "firstTaskA" : {
                //do some stuff
            },
            "secondTaskA" : {
                // Do some other stuff in parallel
            }
        )
    }
}
stage("Stage 2") {
    steps {
        parallel (
            "firstTaskB" : {
                //do some stuff
            },
            "secondTaskB" : { //calls a pipeline job
                // Do some other stuff in parallel
            }
        )
    }
}
post{ //aggregate the results and send an email }
node {
try {

    stage('Clean Work Space') {
        try {
             // Try stage...
        } catch (e) {
            currentBuild.result = "FAILURE"
            throw e
        } finally {
                stage('Cleanup Job workspace') {
                cleanWs()
          }
          if(currentBuild.result == 'FAILURE') {
              // Send email
          }
      }
    }
  }

Work with try, catch and finally and try to catch failures, if you find a failure send an email.

You can send the email in the try, catch or the finally section depends on your email reason.

If you want to single email, use the try, catch and finally on the main node, out side of all stages (wrap the all stages with try, catch and finally).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM