EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Jenkins Email Notification

Home » Software Development » Software Development Tutorials » Jenkins Tutorial » Jenkins Email Notification

Jenkins Email Notification

Introduction to Jenkins Email Notification

Jenkins email notifications is the way to notify based on event occurred or some action happened. Jenkins email notifications is kind of message that is automatically sent to you and update that, there has been activity on one of your social media accounts like Google, slack. As email is the primary means of notification among other social media for Jenkins email notifications. Jenkins provided a plugin to extends functionality of e-mail notifications. It’s basically informing user about some event or status or any information’s that need to be update to their concern users.

3 parts of Jenkins Email Notification

Given below are the 3 parts of jenkins email notification:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • Triggers: This is an defined condition which cause an e-mail notification to be sent.
  • Content: Basically defined content for email subject and body.
  • Recipients: We can mention the concerned user who is supposed to receive an e-mail when any event occurred.

Use Case of Jenkins Email Notification

In any organizations, it follows the devops practice and configured Jenkins as part of their build process. Basically devops team want to configure a process and as part of process to send automated email to the Developers team if any build failure with the help of freestyle configurations. In order to send and receive emails we need to configure email servers in Jenkins. Basically in an organization they have their own email servers that is used to trigger. Emails, in our example we do not have our own server, so we are going to use Gmail SMTP server.

Configure Gmail SMTP Server in Jenkins

After successful installation of Jenkins, it comes with several built in functionalities and several plugins like mail sending. Just we need to configure any plugins or email sending plugin with defined necessary values as in case of email what SMTP server expected.

When the Jenkins email notification triggers, that is an event under which the even occurred and sent to the respective recipients. For Automated build job, there are many events such as success, failure, abort and so on. After clicking on triggers option is basically a selection of required event for which mail need to trigger. Once all the changes are made, save the configurations.

Go to Jenkins dashboard.

Jenkins Email Notification 1

Go to the Jenkins home page and click the ‘Manage Jenkins’ menu option. Then, select the ‘Configure System’ option.

Popular Course in this category
Jenkins Training (4 Courses, 2+ Projects)4 Online Courses | 2 Hands-on Projects | 16+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (5,069 ratings)
Course Price

View Course

Related Courses
Java Training (40 Courses, 29 Projects, 4 Quizzes)All in One Software Development Bundle (600+ Courses, 50+ projects)

Jenkins Email Notification 2

Go to the E-mail notification section and enter the required SMTP server and user email-suffix details. Click the ‘Advanced’ button and then click the checkbox next to the ‘Use SMTP Authentication’ option. Now, set the following fields.

Jenkins Email Notification 3

We have to provide SMTP server details in respective textbox, click on advanced button and below we have fields to be given to configure the SMTP server settings. Please find the below details to configure email server.

Under E-mail Notification, put the mentioned details below:

  • SMTP server → smtp.gmail.com
  • Select Use SMTP Authentication
  • Put your gmail id
  • Put your gmail password
  • Use SSL select
  • SMTP port 465
  • Save the configuration

Jenkins Email Notification 4

To verify the email notification functionality by clicking the checkbox below to the ‘Test configuration by sending Test e-mail recipient’ option.

Enter a valid email id and click the ‘Test configuration’ button to check whether the email id is valid or not.

Checking on the box that is used for SMTP Authentications, to provide the user credentials for the SMTP account.

Jenkins Email Notification 5

Configure jenkins job to trigger email if build fails.

Open your job → Configure → Post Build Actions → Add post-build action → email notification

Jenkins Email Notification 6

Under Recipients put team’s mail id and save the configuration.

Jenkins Email Notification 7

After the successful configuration click on the build now option in order to trigger the build. Based on the build event occurred like success or failed, server send mail to notify.

click on the build now option in order to trigger the build

We can get the build failure notification as failure event occurred at Jenkins server.

build failure notification as failure

Find the use case to send email notification automatically with Pipeline script.

Let’s suppose in any organizations, it follows the devops practice and configured Jenkins as part of their build process. Basically devops team want to configure a process and as part of process to send automated email to the Developers team if build is success.

Configure Jenkins pipeline script job to trigger email if build success.

Please find the below pipeline script:

Code:

node{
stage('SCM Checkout'){
git 'https://github.com/Smaheshwar85/easeWithbase'
}
stage('Compile-Package'){
defmvnHome =  tool name: 'Mavan3', type: 'maven'
sh "${mvnHome}/bin/mvn package"
}
stage('Email Notification'){
mail bcc: '', body: '''Build successful!!!!
Thanks,
Mahesh''', cc: '', from: '', replyTo: '', subject: 'Build successfull', to: 'smahesh2305@gmail.com'
}
}

We have configured the below git repository in above pipeline script. In order to execute pipeline script we created Jenkins file and keep our script in it.

configured the below git repository

Please find the below screen shot for the configurations. We have to define all details under pipeline section. Basically under the repositories section, it was defining the Git repositories path where my Jenkins file was located. Also, we have to mark the branch which was having the updated code and ready for the build. At last needs to be defined the script path which is nothing but the Jenkins file.

Jenkins Email Notification 11

We have defined our email content into the pipeline script, we have received these email content whenever there is any event occurred. As we can see that below email was received as soon as build event was successful.

email was received as soon as build event was successfull

Troubleshooting Tip

If your build is getting failed and you are able to see the below error stack trace in console.

534 5.7.14 https://support.google.com/mail/answer/78754 p10sm11420422qkm.121 – gsmtp

  • at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:809)
  • at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:752)
  • at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:669)
  • at javax.mail.Service.connect(Service.java:317)
  • at javax.mail.Service.connect(Service.java:176)
  • at javax.mail.Service.connect(Service.java:125)
  • at javax.mail.Transport.send0(Transport.java:194)
  • at javax.mail.Transport.send(Transport.java:124)
  • at hudson.tasks.MailSender.run(MailSender.java:130)
  • at hudson.tasks.Mailer.perform(Mailer.java:176)
  • at hudson.tasks.Mailer.perform(Mailer.java:139)
  • at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
  • at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
  • at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690)
  • at hudson.model.Build$BuildExecution.post2(Build.java:186)
  • at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635)
  • at hudson.model.Run.execute(Run.java:1881)
  • at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
  • at hudson.model.ResourceController.execute(ResourceController.java:97)
  • at hudson.model.Executor.run(Executor.java:428)

Finished: FAILURE

In order to fix the above mentioned error kindly follow the below solutions:

This error usually ask for permission to allow the insecure access from the apps.

Step 1: Login to the gmail account you are sending mail from.

Step 2: Go to manage your Google Account -> Security -> Less secure app access -> Turn on access.

Or

Access the URL:

https://www.google.com/settings/security/lesssecureapps

Turn “Allow less secure apps: OFF” to “Allow less secure apps: ON”.

If the tips above didn’t help, visit https://www.google.com/accounts/DisplayUnlockCaptcha and follow the steps on the page.

Recommended Articles

This is a guide to Jenkins Email Notification. Here we discuss the 3 parts of jenkins email notification, use case and configure gmail SMTP server in jenkins. You may also have a look at the following articles to learn more –

  1. Uses of Jenkins
  2. What is Jenkins?
  3. Jenkins Plugins
  4. Jenkins Alternatives

All in One Software Development Bundle (600+ Courses, 50+ projects)

600+ Online Courses

50+ projects

3000+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Jenkins Tutorial
  • Basics
    • What is Jenkins
    • Is Jenkins Free
    • How to Install Jenkins
    • Uses of Jenkins
    • Jenkins Plugins
    • Jenkins Backup
    • Jenkins Email Notification
    • Jenkins Interview Questions

Related Courses

Jenkins Training Course

Java Training Course

Software Development Course Training

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Jenkins Training Course Learn More