How to send notification on fixed build in Jenkins pipeline?

1.4k Views Asked by At

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

There are 1 best solutions below

3
On BEST ANSWER

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.