I'm trying to convert an existing Jenkins Pipeline to the new Declarative Pipeline and I was wondering how to handle correctly mail notifications ?
I'm currently using this code:
node {
try {
...
currentBuild.result = 'SUCCESS'
} catch (any) {
currentBuild.result = 'FAILURE'
throw any
} finally {
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: "baptiste.wicht@gmail.com",
sendToIndividuals: true])
}
}
It works well, but I don't see how to use the new declarative syntax for this. I think something could be done by using post() and the different notifications, but I don't know exactly how. I've tried this:
post {
always {
step([$class: 'Mailer',
notifyEveryUnstableBuild: true,
recipients: "baptiste.wicht@gmail.com",
sendToIndividuals: true])
}
}
But the problem is that it does not send any "Back to normal" mail.
How can I used the Mailer plugin in a Jenkins declarative pipeline in order to send "Back to normal" mails ?
Should use again a try/catch around all declarative syntax ?