0
0
Jenkinsdevops~10 mins

Email notification plugin in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Email notification plugin
Job starts
Build runs
Build finishes
Check build result
Send email
End
The Jenkins job runs a build, then depending on success or failure, it triggers the email notification plugin to send an email.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Building...' }
    }
  }
  post {
    success { mail to: 'team@example.com', subject: 'Build Success', body: 'Good job!' }
    failure { mail to: 'team@example.com', subject: 'Build Failed', body: 'Please check.' }
  }
}
This Jenkins pipeline sends an email after the build stage depending on success or failure.
Process Table
StepBuild StatusCondition CheckedEmail SentEmail Subject
1RunningN/ANoN/A
2SuccessSuccess?YesBuild Success
3SuccessFailure?NoN/A
4EndN/AN/AN/A
💡 Build finished with success, email sent with subject 'Build Success'.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
buildStatusN/ARunningSuccessSuccessSuccess
emailSentNoNoYesYesYes
emailSubjectN/AN/ABuild SuccessBuild SuccessBuild Success
Key Moments - 2 Insights
Why is the email sent only after the build finishes and not during the build?
The execution_table shows that email is sent only after the buildStatus changes to Success or Failure (Step 2), ensuring notifications reflect final build results.
What happens if the build fails? Does the success email get sent?
According to the execution_table, if the build fails, the failure condition triggers email sending, and the success email is not sent (Step 3 shows no success email sent).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the email with subject 'Build Success' sent?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Check the 'Email Sent' and 'Email Subject' columns in execution_table rows.
According to variable_tracker, what is the value of 'buildStatus' after Step 1?
ARunning
BFailure
CSuccess
DN/A
💡 Hint
Look at the 'buildStatus' row under 'After Step 1' in variable_tracker.
If the build failed, which email subject would be sent according to the plugin logic?
ABuild Success
BBuild Failed
CBuild Running
DNo email sent
💡 Hint
Refer to the concept_flow and execution_table showing email subjects for failure.
Concept Snapshot
Jenkins Email Notification Plugin:
- Sends emails after build completion.
- Use 'post' block in pipeline for success/failure.
- 'mail' step sends email with to, subject, body.
- Emails reflect final build status only.
- Helps team stay informed automatically.
Full Transcript
In Jenkins, the Email Notification Plugin sends emails after a build finishes. The pipeline runs the build stage, then checks if the build succeeded or failed. Depending on the result, it sends an email with a subject like 'Build Success' or 'Build Failed'. The execution table shows the build status changing from running to success, triggering the email. Variables track the build status and email details step by step. This ensures notifications only go out after the build is complete, keeping the team updated on results.