DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Jenkins: Integrating Email Service

Jenkins: Integrating Email Service

Setting up email notifications of completed builds from your Jenkins CI is an essential but surprisingly complex process.

Sangeeta Gulia user avatar by
Sangeeta Gulia
·
Mar. 17, 17 · Tutorial
Like (3)
Save
Tweet
Share
38.66K Views

Join the DZone community and get the full member experience.

Join For Free

Jenkins is one open-source tool that can be used to perform Continuous Integration and build automation. Using it, all development work can be integrated as early as possible. The resulting artifacts are automatically created and tested, and as a result, the process of identification of errors becomes faster.

There must be a way that the build status and testing results can be reported to the team. That's when email service comes into the picture.

To dig further into the details of Jenkins and building jobs in it, you can refer to Introduction to Jenkins and Building Jobs With Jenkins.

How can an email service be integrated with Jenkins?

I will be discussing two approaches to configure email services.

  1. Default email notifier. This is what comes default with Jenkins. It contains a default message containing the build number and its status.

  2. Email extension plugin. This plugin allows you to configure every aspect of email notifications. You can customize when an email is sent, who should receive it, and what the email says.

Configuring Default Email Notifier

To provide the configuration, go to the Jenkins System configuration page (Jenkins > Manage Jenkins > Configure System).

You will be able to see the below screen to add email configurations:

1

Below are details for some of the fields:

  • SMTP server: Denotes the name of the mail server. Leave it empty to use the default server (which is normally the one running on localhost). Jenkins uses JavaMail for sending out e-mails, and JavaMail allows additional settings to be given as system properties to the container.

  • SMTP port: Defines the port number for the mail server. Leave it empty to use the default port for the protocol.

Once the mail configurations are set, you can test whether it is working fine or not by checking Test configuration by sending test email.

To allow your projects to send by email, you need to add Post Build Action and select “Email Notification from the drop-down list.

This will provide you the below interface, where you can add a list of email addresses that the email is required to be sent to.

2

Configuring Email Extension Plugin

This plugin extends Jenkins built-in email notification functionality by giving you more control. It provides customization of three areas.

  1. Triggers: Select the conditions that should cause an email notification to be sent.

  2. Content: Specify the content of each triggered email’s subject and body.

  3. Recipients: Specify who should receive an email when it is triggered.

Before using email-ext on a project, you must configure some global settings. Go to the Jenkins System configuration page (Manage Jenkins > Configure System.).

The section titled Extended E-mail Notification is where you can configure global email-ext properties. The properties here should match the settings for your SMTP mail server. This section is set up to mirror Jenkins' own email Publisher Reporter (a different extension point).

However, there are a few additions.

The inputs labeled Default Subject and Default Content allow you to configure the email content on a global level. The input labeled Default Recipients can be used to set a default list of email addresses for all projects using the plugin (it can be overridden at the project level). This can be used to greatly simplify the configuration you need to do for all projects.

3

For a project to use the email-ext plugin, you need to enable it in the project configuration page. Select the checkbox Editable Email Notification in the Post Build Actions section and you will see something like this:

4

There are three fields that you can edit when the plugin is enabled.

  • Global recipient list: This is a comma- or whitespace-separated list of email recipients that allows you to specify a single recipient list for each email that is sent.

  • Default subject: This allows you to configure a token (more about tokens later) that can be used to easily configure all email subjects for the project.

  • Default content: Same as default subject, but for the email body instead of the subject.

Advanced Configuration

To see the advanced configuration for the plugin, click on the Override Global settings checkbox, then click the Advanced button. This section allows you to specify recipients for each type of email trigger as well as a pre-send script that can be used to modify the email just prior to sending.

Triggers

By default, the only trigger configured is the Failure trigger. To add more triggers, select one from the dropdown and it will be added to the list. Once you have added a trigger, you have several options.

References

  • Jenkins Wiki: Email-ext plugin page

Jenkins (software) Continuous Integration/Deployment

Published at DZone with permission of Sangeeta Gulia, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • What Is Policy-as-Code? An Introduction to Open Policy Agent
  • Why It Is Important To Have an Ownership as a DevOps Engineer
  • The Role of Data Governance in Data Strategy: Part II
  • Taming Cloud Costs With Infracost

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: