Overview
In this post, we are going to take a look on how to setup basic email configuration for Jenkins and send mail if build job fails.
First and formost, make sure, you have installed some email plugin so that it will allow you to configure email setup.
You can install any email extension plugin example —
Email Extension – https://plugins.jenkins.io/email-ext/
Or
Mailer – https://plugins.jenkins.io/mailer/
I have installed mailer plugin, once it is installed, it will allow us to setup SMTP settings in Jenkins.
Go to “Manage Jenkins” and then go to “Configure System”
Scroll down at below, there we can see setting for Email notification
We are going to use Gmail as SMTP server here in this post.
Enter information as below
SMTP Server: smtp.gmail.com
click on advance button and fill up information as below
Username: your gmail’s username
Password: your gmail password
Use SSL : checked
SMTP Port: 465
Reply-to-adress: your email address
Now check on : Test configuration by sending test e-mail
It will ask to enter recipient’s email address, enter the address and click on “Test Configuration” button.
It should show – Email was successfully sent
Now our email configuration is completed.
Lets create one freestyle project and add some command in Windows Batch Command as build of project for test.
For build, I have just written simple command as ipconfig
Go to post build action
Click on “Add Post build actions” and select “E-mail notification” there
There, add recipient and click on Save button
Here, we are going to send email if build fails.
Lets build our project.
First run has built successfully.
now go to configure project again and make some mistake in our batch command in build section
here I have added invalid command ipconfig1
Now try to build our project again and you can see build has been failed.
and it has send email to your recipient email address.