Bird
Raised Fist0
Jenkinsdevops~5 mins

Email notification plugin in Jenkins - Commands & Configuration

Choose your learning style10 modes available
Introduction
Sending email notifications helps you know when your Jenkins jobs succeed or fail without checking the dashboard constantly. The Email Notification plugin automates this by sending emails based on job results.
When you want to get an email alert if a build fails so you can fix it quickly.
When you want to notify your team automatically after a successful deployment.
When you want to send a summary email after nightly builds to stakeholders.
When you want to keep track of build status without logging into Jenkins.
When you want to customize who receives emails based on job outcomes.
Config File - Jenkinsfile
Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
    stage('Test') {
      steps {
        echo 'Testing...'
      }
    }
  }
  post {
    success {
      emailext(
        subject: "SUCCESS: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
        body: "Good news! The build succeeded. Check it here: ${env.BUILD_URL}",
        recipientProviders: [[$class: 'DevelopersRecipientProvider']]
      )
    }
    failure {
      emailext(
        subject: "FAILURE: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
        body: "Oops! The build failed. Please check the logs: ${env.BUILD_URL}",
        recipientProviders: [[$class: 'DevelopersRecipientProvider']]
      )
    }
  }
}

This Jenkinsfile defines a simple pipeline with build and test stages.

The post section sends emails after the job finishes.

emailext is used to send emails on success or failure with a subject, body, and recipients set to developers.

Commands
Installs the Email Extension plugin needed to send email notifications from Jenkins.
Terminal
jenkins-plugin-cli --plugins email-ext
Expected OutputExpected
Installing plugin: email-ext Downloading plugin: email-ext Installed plugin: email-ext Restart Jenkins to activate the plugin.
Restarts Jenkins to activate the newly installed Email Extension plugin.
Terminal
jenkins restart
Expected OutputExpected
Jenkins is restarting... Jenkins restarted successfully.
Starts a build of the Jenkins pipeline that includes email notifications.
Terminal
jenkins-cli build my-pipeline
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] echo Building... [Pipeline] echo Testing... [Pipeline] emailext Sending email to developers [Pipeline] End of Pipeline Finished: SUCCESS
Shows the console output of the last build to verify email steps ran.
Terminal
jenkins-cli console my-pipeline
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] echo Building... [Pipeline] echo Testing... [Pipeline] emailext Sending email to developers [Pipeline] End of Pipeline Finished: SUCCESS
Key Concept

If you remember nothing else from this pattern, remember: configure email notifications in the post-build section to automatically alert on build success or failure.

Common Mistakes
Not installing the Email Extension plugin before using emailext in the Jenkinsfile.
The emailext step will fail because Jenkins does not recognize it without the plugin.
Install the email-ext plugin using jenkins-plugin-cli and restart Jenkins before using emailext.
Forgetting to configure SMTP server settings in Jenkins global configuration.
Emails will not send because Jenkins cannot connect to an email server.
Set up SMTP server details under Manage Jenkins > Configure System before running jobs with email notifications.
Using incorrect recipientProviders or missing recipient emails.
Emails may not reach intended recipients or fail silently.
Use valid recipientProviders like DevelopersRecipientProvider or specify recipient emails explicitly.
Summary
Install the Email Extension plugin and restart Jenkins to enable email notifications.
Add emailext steps in the post section of your Jenkinsfile to send emails on success or failure.
Verify the pipeline runs and emails are sent by checking the console output and email inbox.

Practice

(1/5)
1. What is the main purpose of the Jenkins Email Notification plugin?
easy
A. To deploy applications to servers
B. To automatically send emails about build status
C. To monitor server CPU usage
D. To create new Jenkins jobs

Solution

  1. Step 1: Understand the plugin's function

    The Email Notification plugin is designed to send emails automatically when a build finishes.
  2. Step 2: Identify the correct purpose

    It helps keep the team informed by sending build status emails without manual effort.
  3. Final Answer:

    To automatically send emails about build status -> Option B
  4. Quick Check:

    Email Notification plugin = automatic build emails [OK]
Hint: Email plugin = auto send build status emails [OK]
Common Mistakes:
  • Confusing with deployment tools
  • Thinking it monitors server health
  • Assuming it creates jobs
2. Which of the following is the correct syntax to enable email notifications in a Jenkins pipeline script?
easy
A. sendEmail(subject: 'Build Status', body: 'Build completed', to: 'team@example.com')
B. emailNotify(subject: 'Build Status', body: 'Build completed', to: 'team@example.com')
C. emailext(subject: 'Build Status', body: 'Build completed', to: 'team@example.com')
D. notifyEmail(subject: 'Build Status', body: 'Build completed', to: 'team@example.com')

Solution

  1. Step 1: Recall Jenkins pipeline email syntax

    The Email Extension plugin uses the emailext step to send emails.
  2. Step 2: Match the correct function name and parameters

    Only emailext(subject: 'Build Status', body: 'Build completed', to: 'team@example.com') uses emailext with correct parameters: subject, body, and to.
  3. Final Answer:

    emailext(subject: 'Build Status', body: 'Build completed', to: 'team@example.com') -> Option C
  4. Quick Check:

    Use emailext for email notifications [OK]
Hint: Use 'emailext' step for Jenkins email notifications [OK]
Common Mistakes:
  • Using incorrect function names
  • Missing required parameters
  • Confusing with other plugins
3. Given this Jenkins pipeline snippet:
pipeline {
  agent any
  stages {
    stage('Build') {
      steps {
        echo 'Building...'
      }
    }
  }
  post {
    failure {
      emailext(
        subject: 'Build Failed',
        body: 'Please check the build logs.',
        to: 'devteam@example.com'
      )
    }
  }
}

What happens if the build fails?
medium
A. An email with subject 'Build Failed' is sent to devteam@example.com
B. No email is sent because the syntax is wrong
C. An email is sent only if the build succeeds
D. The build will retry automatically

Solution

  1. Step 1: Analyze the post-failure block

    The post { failure { ... } } block runs only if the build fails.
  2. Step 2: Understand the emailext usage

    The emailext step sends an email with the given subject and body to the specified address.
  3. Final Answer:

    An email with subject 'Build Failed' is sent to devteam@example.com -> Option A
  4. Quick Check:

    Post failure triggers email = An email with subject 'Build Failed' is sent to devteam@example.com [OK]
Hint: Post failure block sends email on build failure [OK]
Common Mistakes:
  • Thinking email sends on success
  • Assuming syntax error without checking
  • Confusing retry with email notification
4. You configured the Email Notification plugin but no emails are sent after build failures. Which is the most likely cause?
medium
A. SMTP server settings are missing or incorrect
B. The Jenkins job has no build steps
C. The build always succeeds
D. The plugin is not installed

Solution

  1. Step 1: Check email sending prerequisites

    Jenkins needs correct SMTP server settings to send emails.
  2. Step 2: Identify common misconfiguration

    If SMTP settings are missing or wrong, emails won't send even if plugin is configured.
  3. Final Answer:

    SMTP server settings are missing or incorrect -> Option A
  4. Quick Check:

    SMTP config missing = no emails sent [OK]
Hint: Verify SMTP settings to fix email sending issues [OK]
Common Mistakes:
  • Ignoring SMTP configuration
  • Assuming plugin auto-configures SMTP
  • Thinking build steps affect email sending
5. You want to send an email notification only when the build status changes (e.g., from success to failure or failure to success). Which Email Notification plugin feature should you use?
hard
A. Use the 'Send e-mail for every unstable build' option
B. Use the 'Always send e-mail' option
C. Configure a post-build script to check status manually
D. Enable 'Send e-mail only on status change' in the plugin settings

Solution

  1. Step 1: Understand the requirement

    The goal is to send emails only when build status changes, not every build.
  2. Step 2: Identify plugin feature for status change

    The Email Notification plugin has an option named 'Send e-mail only on status change' to handle this.
  3. Step 3: Compare other options

    Options A and D send emails more frequently; Configure a post-build script to check status manually requires manual scripting.
  4. Final Answer:

    Enable 'Send e-mail only on status change' in the plugin settings -> Option D
  5. Quick Check:

    Status change emails = enable plugin's status change option [OK]
Hint: Enable 'send only on status change' to reduce email noise [OK]
Common Mistakes:
  • Choosing options that send emails every build
  • Ignoring built-in plugin features
  • Overcomplicating with manual scripts
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard