0
0
Jenkinsdevops~30 mins

Email notifications in pipelines in Jenkins - Mini Project: Build & Apply

Choose your learning style9 modes available
Email notifications in pipelines
📖 Scenario: You are setting up a Jenkins pipeline for a software project. You want to send email notifications to the team when the build finishes, so everyone knows if it succeeded or failed.
🎯 Goal: Build a Jenkins pipeline script that sends an email notification with a fixed subject and recipient after the build completes.
📋 What You'll Learn
Create a Jenkins pipeline script with a pipeline block
Define an agent to run the pipeline
Add a stage called Build with a simple shell command
Add a post section to send an email notification after the build
Use the mail step with exact parameters for recipient and subject
💡 Why This Matters
🌍 Real World
Teams use Jenkins pipelines to automate software builds and tests. Sending email notifications keeps everyone informed about build results without checking Jenkins manually.
💼 Career
Knowing how to configure email notifications in Jenkins pipelines is a common DevOps task. It helps maintain communication and quick feedback in software delivery.
Progress0 / 4 steps
1
Create the basic Jenkins pipeline structure
Write a Jenkins pipeline script with a pipeline block and an agent any declaration.
Jenkins
Need a hint?

Start by writing pipeline { and inside it add agent any to run on any available node.

2
Add a Build stage with a shell command
Inside the pipeline block, add a stages section with one stage named Build. Inside it, add a steps block that runs the shell command echo "Building project".
Jenkins
Need a hint?

Use stages {} to group stages, then add stage('Build') {}. Inside steps {}, use sh 'echo "Building project"' to run the shell command.

3
Add a post section to send email after build
Add a post section inside the pipeline block. Inside post, add an always block that calls the mail step with to: 'team@example.com', subject: 'Build Notification', and body: 'The build has completed.'.
Jenkins
Need a hint?

Use post { always { ... } } to run steps after the build finishes. Inside, call mail with the exact parameters.

4
Print confirmation message after sending email
Add a echo step inside the always block after the mail step to print 'Email notification sent.'.
Jenkins
Need a hint?

Use echo 'Email notification sent.' to print a confirmation message after sending the email.