I’m trying to set up my Jenkins pipeline to send me an email notification under specific conditions, but I’m not sure of the best way to configure this. Ideally, I’d like to be notified:
When the pipeline completes successfully,
If the pipeline fails,
And, if possible, only receive notifications for certain stages.
I’ve already installed the Email Extension Plugin and Mailer Plugin, but I’m a bit lost on how to integrate them properly in the pipeline code (Jenkinsfile). Should I be using post conditions, or is there another approach recommended?
Could someone provide an example of how to configure this in the Jenkinsfile? Or any tips for managing notification frequency so I’m not overwhelmed with emails?
I’m having the same issue. I setup the email extension plugin correctly but no email are sent out. The error is saying “Template with ID ‘emailext-template-1566911940877’ is not available, perhaps it was removed?”
The email-ext plugin provides a step that you can use in your pipeline, figuring out how to get it sent when you want is the “tricky” part.
To send when your pipeline succeeds/fails/etc, you can use the post construct which can be used at the top level under pipeline or an individual stage which should allow you to get the overall pipeline notification as well as individual stages as you mentioned in your post.
It looks like you are trying to use a template, but the template doesn’t exist. I think you need to start your own thread on here as your issue is not the same as @RimDammak
As @slide_o_mix mentioned, you can call emailext() from a regular steps {} block or from a post {} block for the entire pipeline or for each stage {} block.
I wish the jenkins documentation had more examples in general. As you have experienced, the documentation for emailext() is rather obscure on how to actually use it.
Thank you all for the detailed explanation, provided code, and valuable feedback.
I would greatly appreciate if you could create a pull request to add the relevant documentation to either the jenkins.io repository or the email-ext-plugin documentation. This will help ensure the information is readily available to the wider Jenkins community.
Please let me know if you have any questions or need further assistance.