How to Configure Jenkins Mail Notification on Build Failures

This tutorial post will show you How to Configure Jenkins Mail notification for Build Failures.
When there is a build failure or any changes in the build state, we must get notified immediately through e-mail. so that we can fix the issue at the earliest. There is a mailer plugin available in Jenkins that has be installed and configure it based on the requirement.

If you are interested in learning, Request you to go through the below recommended tutorial.

How to Configure Jenkins Mail Notification on Build Failures

How to Configure Jenkins Mail Notification on Build Failures
Also You can Watch this Tutorial video on our YouTube Channel.
How to Configure Jenkins Mail Notification for Any Build Failures | Jenkins Tutorial

Let’s get started.

Once you have logged into Jenkins portal with valid credentials.

jenkins dashboard gui

Step 1: Install Mailer Plugin for Jenkins Mail Notification.
Go to “Manage Jenkins” available at the left side panel.

jenkins portal main screen

Select “Manage Plugins” from the Manage Jenkins Page.

jenkins manage plugins

Go to “Available” tab and Search for “mailer” plugin in filter. Select the plugin “Mailer” and Click “Install without restart”.

jenkins%2Bmailer%2Bplugins

Selected plugin and its required dependencies also will be installed.

mailer%2Bplugin%2Binstalled%2Bin%2Bjenkins

Once the “mailer” plugin is installed. Click “Go back  to the top page”, this will take you to the main page of jenkins.

Step 2 : Configure Mail with SMTP authentication
Again go to “Manage Jenkins” and select “Configure System”.

jenkins%2Bconfigure%2Bsystems%2Bin%2Bmanage%2Bjenkins

Scroll down to find the field “Jenkins Location” and change “System Admin e-mail address” with your Name and E-mail address in the same format as shown in the below image. Because, this is the information about sender and sender mail address.

Now, Enter your SMTP Server name  in the field “SMTP Server”. For this example, I use my personal gmail address to get the mail notification, So I used gmail smtp server. Once this is completed, click “Advanced” button to provide the authentication details.

jenkins%2Bmail%2Bnotification%2Boptions

1. Enable “Use SMTP Authentication”
2. Enter your E-mail ID or username.
3. Enter your password.
4. Mark to “Use SSL”.
5. Enter your SMTP Server Port Number.

Jenkins%2BSmtp%2BMail%2BConfiguration

Once above required information are given, We can check the configuration by sending a test mail.

So, select the option “Test configuration by sending test e-mail” and enter your mail address, click “Test Configuration” button to ensure the mail configuration works properly or not. If everything is ok, you will get an test e-mail from this jenkins server. Finally click “Save”.

Jenkins%2BTest%2BMail%2BConfiguration

Step 3 : Configure Jenkins Job Notification

Let’s go back to main jenkins job queue and select the job which require notification.

jenkins%2Bmain%2Bjob%2Bqueue

Select “Configure”.

Configure%2Bjenkins%2Bjob

Go to “Post Build Actions”

jenkins%2Bjobs%2Ball%2Bmenus

Select “Add post-build action” and Click “E-Mail Notification”.

jenkins%2Bmail%2B%2Bnotification%2Boptions

Enter your recipients mail address and select first option “Send e-mail for every unstable build”. Click “Save” button.

But, If the second option “Send separate e-mails to individuals who broke the build” is checked, the notification e-mail will be sent to individuals who have committed changes for the broken build (by assuming that those changes broke the build).

If e-mail addresses are also specified in the recipient list, then both the individuals as well as the specified addresses get the notification e-mail. If the recipient list is empty, then only the individuals will receive e-mails.

jenkins%2Bmail%2Bnotification%2Bfor%2Bfailed%2Bjob

So we have configured mail notification for build jobs. If there is any failure in build or any changes in build state from failure to success or success to failure, you would get an mail notification.

jenkins%2Bbuild%2Bfailure%2Band%2Bbuild%2Bstate%2Bchanges

Sample mail for build failure.

Jenkins%2Bbuild%2Bfailed%2Bmail%2Bnotification

Sample mail for build state changes.

Jenkins%2Bbuild%2Bstate%2Bback%2Bto%2Bnormal

Hope you have got an idea how to configure Jenkins mail notification for any build failure and build state changes. Going forward we will play more with Jenkins integration tool.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.