top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Configure Jenkins (CI/CD) to send the Build Status, Reports and Logs to Email

Jenkins is an open source automation tool that developers can use to build and test software projects, making it simpler for them to incorporate changes. Jenkins achieves Continuous integration and Continuous Deployment with the help of plugins. Every tool that has to be integrated has its own set of plugins. When Maven and Jenkins are connected via plugins, the entire build process may be automated.


In real time it is very important to generate reports for the tests we performed and also to send them to the team to check the status especially in failure/unstable scenarios. In Selenium, we have three options to notify the test results.

  1. Configure Jenkins (CI/CD) to send the reports

  2. Send mail using java code ( JavaAPI)

  3. To use Maven Post-Man plugin to send reports using eclipse


Configure Jenkins (CI/CD) to send the reports

In this blog, we are discussing the first option. how to do email configuration in Jenkins and send the status/logs/reports through email. Here we are using Gmail to configure and send the mails.


Step - 1: Email Plugins

  1. Go to Jenkins Dashboard → Manage Plugins → click on ‘Plugins’ under System Configuration.

  2. Now check if the “Email Extension Plugin” is installed under Installed Plugins. 

If not, go to Available Plugins and search for “Email Extension Plugin” and install.



Step - 2: Email Notification

  1. Go Back to Manage Jenkins and click on ‘System’ under System Configuration.

  2. Now scroll down and go to ‘Email Notification’ and configure it as below

  • Enter the SMTP server name as smtp.gmail.com.

  • Click Advanced and Select Use SMTP Authentication & Use SSL options

  • Enter your Gmail ID and password under Use SMTP Authentication

  • Enter 465 as the SMTP port. This is for Gmail.

  • Enter your email ID as the Reply-to-Address.

  • Click Save.


  1. Enter your Gmail id and click on test configuration. It will send a test email to your account if entered data is valid. Otherwise it throws errors as below.


Errors: There may be below errors while sending Test Email from Jenkins-

  1. Failed to send out e-mail

jakarta.mail.AuthenticationFailedException: 534-5.7.9 Application-specific password required. Learn more at 534 5.7.9  https://support.google.com/mail/?p=In... ix12-20020a170902f80c00b001b53953f306sm2455601plb.178 - gsmtp

 at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:947)

 at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858)

 at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:762)

 at jakarta.mail.Service.connect(Service.java:364)

  1.  jakarta.mail.AuthenticationFailedException: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8  https://support.google.com/mail/?p=Ba... v10-20020a17090ac90a00b002801ca4fad2sm1308228pjt.10 - gsmtp

 at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:947)

 at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858)


To resolve/fix such error, follow the below steps

Go to your Google/gmail Account → Manage your Google Account → Security → Under How you sign into Google → select 2-Step Verification.

At the bottom of the page → select App passwords → Enter a name that helps you remember where you’ll use the app password → Select Create, it generates a 16 digit password.

Copy that password and save it in Notepad. Now Add the app password for SMTP GMAIL account instead of your GMAIL account password


Now re enter the Gmail under test configuration and check if you received the test email.



Step - 3: Extend Email Notification

  1. Go Back to Manage Jenkins and click on ‘System’ under System Configuration.

  2. Now scroll down and go to ‘Extend Email Notification’ and configure it as below.

  • Enter the SMTP server name as smtp.gmail.com.

  • Enter 465 as the SMTP port. This is for Gmail.

  • Click Advanced and Select Use SSL option. 

  • Click on Add → Jenkins → Enter Username and Password [same email and password should be used from Email Notification part from step-2] → Click Add.

  • Now choose the one you created from the dropdown under Credentials.


  1. Choose Default Content Type as Plain Text/HTML as you need.

  2. Enter email ID in Default Recipients (optional), Reply To List


  1. You can change the Default Subject and Default Content as you need or Keep it as it is. 

Here is the Jenkins Set Environment Variables link to know how to use PROJECT_NAME, BUILD_NUMBER etc., 



  1. Now scroll down a little and dropdown Default Triggers, choose as required. Below I have chosen Always, Failure - Any, Success, Unstable related options as per my requirement.


  1. Once setup is completed, click on Apply and Save.

Step - 4: Configure Email Notification/Editable Email Notification

  1. Go to your project → click Configure → Build Settings

  2. Under Email Notifications enter your mail and select options as required.


  1. Go to Post-build Actions → Add post-build action → choose “Editable Email Notification

  2. Add the details as below. Enter the mail ID in Project From, Project Recipient List, Project Reply-To List. Choose Content Type, Default Subject and Default content as you need. Otherwise keep the default values. 


  1. If you want to send the reports in email, enter the location of the report under Attachments as shown above screenshot. You can add multiple reports/files locations.

Also you can send the build logs by choosing the option ‘Attach Build Log’ under Attach Build Log.



  1. Go to Advanced Settings → Triggers → Add ‘Recipient List’ as Send To. Now drop down Advanced → enter the email in the Recipient List. Choose the other options as required. 

You can add multiple Send To options like Developers etc. 

Repeat the same for other Triggers as well.



  1. Once all details are filled, Click Apply and Save.

Step - 5: Build the Project and verify your Email

  1. Go to Dashboard → Choose your Project → click on ‘Build Now’.

  2. Once build is completed (Success/Failure/Unstable) and reports are generated, Check your Gmail account.

  3. You will get single or multiple notification emails with Status, attached Logs and Report(based on your configuration).

Also you can check the status in Console output.



Advantages

  • Email makes it easier for the team to monitor the job.

  • Multiple events can be triggered by making use of the plugin, which helps to monitor the job easily.

  • Jobs that take a long time to run won’t need continuous attention from the team. Once completed (irrespective of the result) it will trigger the email to notify the team.


Conclusion:

In conclusion, how to configure and send email through Jenkins (CI/CD) has been demonstrated. This helps to send the status of the project, generated reports and Build logs. It makes it easier for a developer/tester or any team member to check the status of the project (Success/Failure/Unstable/Stable) through email notification. Here we have used Gmail to configure and send the mails. It usually depends on the company which mail to be used and based on that server and port number details will be changed. Common errors details also have been explained. Hope it helps, Happy Learning..!


References: 

Below links help you how to install Jenkins, integrate project and reports with Jenkins 


183 views2 comments

Recent Posts

See All

2 Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
Rated 5 out of 5 stars.

Well written and readily comprehensible!

Like

Rated 5 out of 5 stars.

Useful Information . Thank you Harika.

Like
bottom of page