Blog

Blog

How To Configure Email Notification In Jenkins In 6 Simple Steps?

Configure Email Notification In Jenkins

Configure Email Notification In Jenkins

Why do we need email notifications in Jenkins?

Jenkins is a popular open-source automation server that is used for continuous integration and continuous delivery (CI/CD) workflows. It is often used in software development projects to automate the building, testing, and deployment of code.

Email notifications are an important feature in Jenkins because they allow developers, testers, and stakeholders to stay informed about the status of Jenkins builds and deployments. Email notifications can be sent automatically when a build succeeds, fails, or encounters other issues. This allows team members to quickly identify and address any problems with the build, and can help prevent issues from escalating.

In addition to providing notifications about build status, email notifications can also be used to provide more detailed information about build failures, including error messages and log files. This information can be valuable for troubleshooting and debugging build issues.

image

How To Send Email Notification In Jenkins?

Jenkins provides several ways to send email notifications, including the Default Email Notifier and the Email Extension Plugin.

Default Email Notifier

The Default Email Notifier is a basic email notification plugin that is included with Jenkins by default. It allows you to configure email notifications for individual jobs or for the entire Jenkins instance.

To configure email notifications using the Default Email Notifier, follow these steps:

  1. Navigate to the Jenkins dashboard and select the job you want to configure.
  2. Click on “Configure” to open the job configuration page.
  3. Scroll down to the “Post-build Actions” section and select “E-mail Notification”.
  4. Enter the email address(es) of the recipient(s) in the “E-mail Notification” field.
  5. Save your configuration changes.

Once you have configured email notifications for a job, Jenkins will automatically send an email when the job completes, either successfully or with a failure.

Email Extension Plugin

The Email Extension Plugin is a more advanced email notification plugin that provides additional features and customization options. It allows you to send customized email notifications with attachments, custom email templates, and more.

To configure email notifications using the Email Extension Plugin, follow these steps:

  1. Install the Email Extension Plugin from the Jenkins plugin manager.
  2. Navigate to the Jenkins dashboard and select the job you want to configure.
  3. Click on “Configure” to open the job configuration page.
  4. Scroll down to the “Post-build Actions” section and select “Editable Email Notification”.
  5. Configure the email notification settings as desired, including the recipient(s), subject, body, and attachments.
  6. Save your configuration changes.

Once you have configured email notifications using the Email Extension Plugin, Jenkins will automatically send customized email notifications when the job completes.

Overall, email notifications are an essential feature in Jenkins that can help keep teams informed about the status of builds and deployments. Whether you use the Default Email Notifier or the Email Extension Plugin, Jenkins provides a range of options for configuring email notifications that can be customized to meet your specific needs.

image

The process of configuring email notifications in Jenkins. Here are the 6 simple steps you can follow:

Step 1: Install the Email Extension Plugin

The first step is to install the Email Extension Plugin in Jenkins. This plugin allows you to customize email notifications and send them to specific recipients. To install this plugin, follow these steps:

  1. Open Jenkins and click on the “Manage Jenkins” option from the left-hand menu.
  2. Click on “Manage Plugins” from the options presented.
  3. In the “Available” tab, search for “Email Extension Plugin”.
  4. Check the box next to the plugin and click on the “Install without restart” button.

Once the plugin is installed, you should see a new “Extended E-mail Notification” option in the Jenkins configuration menu.

Step 2: Configure Email Settings

Before you can send email notifications, you need to configure the email settings in Jenkins. To do this, follow these steps:

  1. Click on “Manage Jenkins” and then “Configure System”.
  2. Scroll down to the “Extended E-mail Notification” section and click on “Advanced”.
  3. Enter the SMTP server address for your email provider in the “SMTP server” field.
  4. Enter the port number for your SMTP server in the “SMTP port” field.
  5. Choose the appropriate encryption method for your email provider in the “Use SSL” or “Use TLS” field.
  6. Enter your email address in the “Default user e-mail suffix” field.

Step 3: Create an Email Template

The Email Extension Plugin allows you to create custom email templates for your notifications. To create a template, follow these steps:

  1. Click on “Manage Jenkins” and then “Configure System”.
  2. Scroll down to the “Extended E-mail Notification” section and click on “Advanced”.
  3. Click on “Add” under the “Default Content” section.
  4. Enter a name for the template in the “Name” field.
  5. Enter the email subject in the “Subject” field.
  6. Enter the email body in the “Content” field. You can use variables to insert dynamic content into the email.

Here is an example email template that includes the build status and a link to the build console:

bash
${BUILD_STATUS}: Job ${JOB_NAME} [${BUILD_NUMBER}]
Check console output at ${BUILD_URL} to view the results.

Step 4: Add Post-Build Actions

To send email notifications after a build is completed, you need to add post-build actions to your Jenkins job. To do this, follow these steps:

  1. Open the Jenkins job you want to configure.
  2. Click on “Configure” from the left-hand menu.
  3. Scroll down to the “Post-build Actions” section and click on “Add post-build action”.
  4. Select “Editable Email Notification” from the list of options.

Step 5: Configure Email Recipients

You can configure email recipients for your notifications using the Email Extension Plugin. To do this, follow these steps:

  1. In the “Editable Email Notification” section, scroll down to the “Project Recipient List” field.
  2. Enter the email addresses of the recipients you want to notify. You can separate multiple addresses with a comma.
  3. You can also configure email addresses based on the build status, using the “Recipient List” and “Trigger for matrix projects” fields.

Here is an example of how to configure email recipients based on the build status:

perl
${BUILD_STATUS == "FAILURE" ? "[email protected]" : ""}

This code will send the email to the “[email protected]” address if the build fails, and will not send an email if the build succeeds.

Step 6: Save and Test the Configuration

Finally, you need to save your configuration and test the email notification by running a build. To do this, follow these steps:

  1. Click on the “Save” button to save your configuration changes.
  2. Run a build for the Jenkins job you just configured.
  3. Once the build is completed, check your email inbox to see if you received the notification.

If you did not receive the email, check the Jenkins console output for any error messages related to the email notification. You may need to double-check your email settings and configuration.

Here’s an example of how the console output might look if the email notification was successful:

yaml
Email was triggered for: Success - Job 1 #1Sending email to: [email protected]: SUCCESS

That’s it! You have successfully configured email notifications in Jenkins using the Email Extension Plugin. You can customize your notifications further by adding attachments, using email triggers, and more.

Here’s an example of how to add an attachment to your email notification:

  1. In the “Editable Email Notification” section, scroll down to the “Attachments” field.
  2. Click on “Add” and enter the file path of the attachment you want to include. You can use variables to specify the file path, such as ${WORKSPACE}/report.pdf.
image

Here’s an example of how to use email triggers to send notifications only when certain conditions are met:

  1. In the “Editable Email Notification” section, scroll down to the “Triggers” field.
  2. Click on “Add Trigger” and select the trigger type you want to use, such as “Failure – Any”.
  3. Configure the trigger settings as needed, such as specifying a threshold for the build result.
  4. Save your configuration and run a build to test the email trigger.

Here’s an example of how to use the Jenkins pipeline syntax to send email notifications:

php
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'make'
            }
        }
    }
    post {
        always {
            emailext (
                subject: 'Build Notification',
                body: 'The build is complete.',
                to: '[email protected]',
                attachmentsPattern: '**/*.log'
            )
        }
    }
}

In this example, the “emailext” post-build action is used to send an email notification with the specified subject, body, recipient, and attachment pattern.

I hope this helps! Let me know if you have any further questions.

Conclusion:

In conclusion, setting up email notifications in Jenkins is a straightforward process that can be completed in just a few steps:

  1. Install and configure the Email Extension Plugin
  2. Configure the SMTP server settings
  3. Configure Jenkins global email notification settings
  4. Add email notifications to individual jobs
  5. Customize email content and recipients as needed
  6. Test the email notification system

By following these six steps, you can ensure that you and your team are always up-to-date on the status of your Jenkins builds and can quickly address any issues that arise. With email notifications in place, you can save time and improve your overall development workflow.

Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Subscribe to Newsletter

Stay ahead of the rapidly evolving world of technology with our news letters. Subscribe now!