Details
-
Bug
-
Status: Resolved (View Workflow)
-
Minor
-
Resolution: Won't Fix
-
Jenkins 2.14 running in docker container
Mailer plugin 1.17
Pipeline: API 2.1
Description
Mailer doesn't send "back to normal" email, when pipeline gets green after failed build.
The "failed build" email is send properly.
The issue occurs only if plugin is used inside pipeline script.
Example to reproduce:
node { catchError { stage "random fail" Random random = new Random(); int randomNumber = random.nextInt(10 - 1) + 1; echo "${randomNumber}" if (randomNumber > 5) { echo "in loop" currentBuild.result = 'FAILURE' error "failed" } } echo "after finally" step([$class: 'Mailer', recipients: 'tomasz.pietrek@sap.com']) }
The same issue occurs if code is wrapped with try, catch, finally instead of catchError
I had the same issue.
I found some topics on google that explained tha this is because the currentBuild.result is not yet set and null.
Your Failure works because you set it yourself.
In my side, my workaround is to wrap the whole pipeline in a try / catch / finally.
If the pipeline fall in the catch, that means that an exception is thrown so i mark the build as failed.
In the finally, if currentBuil.result is null, I assume that it should be SUCCESS, so I set it myself.
Then, again in the finally block, I call the Mailer step.
It works for both, failures an back to stable notifications.
It us a workaround.
I'm not a big fan of bypassing the pipeline final result management.
I don't know if something can be done to not have to do it.