Jenkins – Integrating Email Service


Jenkins is one open source tool 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. But there must be a way so that build status and testing results can be reported to the team. And then email service come into 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.

Now the next question comes i.e “ How email service can be integrated with Jenkins? ”

So I will be discussing two approaches to configure email service:

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.

Next step will be, what all configurations we require to use the above two.

Configuring Default Email Notifier

Step 1: Configure Default Email Notifier

To provide the configuration, Go to Jenkins System configuration page:

Jenkins -> Manage Jenkins -> Configure System

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

1

Below is the detail for some of the fields :

  • SMTP Server: It denotes 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: It define 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”.

Step 2: To add email notification to projects

To allow your projects to send 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 list of email addresses to whom email is required to be sent.

2

Configuring Email Extension Plugin

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

  • Triggers – Select the conditions that should cause an email notification to be sent.

  • Content – Specify the content of each triggered email’s subject and body.

  • Recipients- Specify who should receive an email when it is triggered.

Step 1: Set Global Configuration

Before using email-ext on a project, you must configure some global settings. Go to Jenkins System configuration page i.e, 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 (It’s 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 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

Step 2: Project configuration

For a project to use the email-ext plugin, you need to enable it in the project configuration page. Select the checkbox labelled “Editable Email Notification” in the “Post-build Actions” section and you will be able to see something like below screenshot.

4

Basic Configuration

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. 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, first click on Override Global setting 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:

1) https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin


KNOLDUS-advt-sticker

This entry was posted in testing, Tutorial and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s