Reputation: 123
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 }
Upvotes: 0
Views: 586
Reputation: 457
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).
Upvotes: 0