Jenkins Email Notification

Jenkins Email Notification
Written by Sagar RabidasJanuary 3, 2022
10 min read
Jenkins
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Sagar Rabidas

Software Developer

In this blog, we will discuss Jenkins Email Notification

Jenkins:-

Jenkins is an open-source non-stop integration server written in java for orchestrating a sequence of actions to attain the continuous integration technique in an automated style. Jenkins helps the complete improvement lifestyles cycle of software program from constructing, testing, documenting the software program, deploying, and different stages of the software improvement existence cycle.

Jenkins is a widely used application around the world that has around 300k installations and growing day by day. By using Jenkins, software companies can accelerate their software development process, as Jenkins can automate build and test at a rapid rate.

It's far a server-based application and requires a web server like apache tomcat. The purpose Jenkins software program becoming so famous is that of its tracking of repeated responsibilities that arise throughout the development of a challenge. For example, in case your group is developing an undertaking, Jenkins will constantly take a look at your task builds and show you the mistakes in the early stages of your development.

blogpost

Jenkins Email Notification:-

Jenkins Email Notifications are the way to notify based on an event that occurred or some action that happened. Jenkins email notifications are the 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 extend the functionality of e-mail notifications. It’s informing the user about some event or status or any information that needs to be updated to their concerned users.

3 parts of Jenkins Email Notification

Given below are the 3 parts of Jenkins email notification:

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

Use Case of Jenkins Email Notification

Any organization follows the DevOps practice and configured Jenkins as part of their build process. DevOps team wants to configure a process and as part of the process to send an automated email to the Developers team if any build failure with the help of freestyle configurations. To send and receive emails we need to configure email servers in Jenkins. Basically in an organization, they have their email servers that are used to trigger. Emails, in our example we do not have our server, so we are going to use a 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 plugins with defined necessary values as in case of the email what SMTP server expected.

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

  • Go to Jenkins dashboard.
  • Go to the Jenkins home page and click the ‘Manage Jenkins’ menu option. Then, select the ‘Configure System’ option.
  • 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.
  • We have to provide SMTP server details in the respective textbox, click on the advanced button, and below we have fields to be given to configure the SMTP server settings. Please find the below details to configure the email server.

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

  1. SMTP server → smtp.gmail.com
  2. Select Use SMTP Authentication
  3. Put your Gmail id
  4. Put your Gmail password
  5. Use SSL select
  6. SMTP port 465
  7. Save the configuration
  • 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.
  • Configure Jenkins job to trigger an email if the build fails.
  • Open your job → Configure → Post Build Actions → Add post-build action → email notification
  • Under Recipients put team’s mail id and save the configuration.
  • After the successful configuration click on the build now option to trigger the build. Based on the build event that occurred like success or failure, the server sends mail to notify.
  • We can get the build failure notification as a failure event occurred at the Jenkins server.

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

Let’s suppose in any organization, it follows the DevOps practice and configured Jenkins as part of their build process. DevOps team wants to configure a process and as part of the process to send an automated email to the Developers team if the build is successful.

Configure Jenkins pipeline script job to trigger an 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'
}
}

Troubleshooting Tip

If your build is getting failed and you can see the below error stack trace in the 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)
Jenkins
Email Notification
JenkinsX
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
You must be Logged in to comment
Code Block
Techiio

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

facebooklinkdeintwitter

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Copyright techiio.com @2020 Kolkata, India
made with by Abhishek & Priyanka Jalan
Copyright techiio.com @2020
made with by Abhishek & Priyanka Jalan