0
votes

I'm trying to use email notifications in my Jenkins pipeline. What I want is to send a notification on failed build and a notification on fixed build. The first is really easy with a try/catch or catchError but I haven't found a solution for the latter.

Is it possible to send a notification for fixed builds in a Jenkins Pipeline ?

1

1 Answers

4
votes

You can use Jenkins Class Mailer to accomplish what you want by calling Mailer:

step([$class: 'Mailer',
      notifyEveryUnstableBuild: true,
      recipients: "[email protected]",
      sendToIndividuals: true])

in your try/catch/finally clause in finally. Mailer sends emails on fixed builds(by itself):

  1. A successful build after a failed (or unstable) build triggers a new e-mail, indicating that a crisis is over.

Another way is to manually check the status of the previous build and the current build and if they satisfy your requirements, then you send the email. You can do that following this resolution.