0
0
Jenkinsdevops~5 mins

Why notifications matter in Jenkins - Why It Works

Choose your learning style9 modes available
Introduction
Notifications in Jenkins help teams know immediately when a build or deployment succeeds or fails. This quick feedback prevents delays and keeps everyone informed about the project's health.
When a build fails and the team needs to fix it quickly to avoid blocking other work
When a deployment completes successfully and the team wants confirmation
When a test run finishes so developers can check results without manually looking
When a critical job is unstable and requires immediate attention
When team members work remotely and need alerts on their devices
Config File - Jenkinsfile
Jenkinsfile
pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                echo 'Building...'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing...'
            }
        }
    }
    post {
        success {
            mail to: 'team@example.com',
                 subject: "SUCCESS: Build ${env.JOB_NAME} #${env.BUILD_NUMBER}",
                 body: "Good news! The build succeeded."
        }
        failure {
            mail to: 'team@example.com',
                 subject: "FAILURE: Build ${env.JOB_NAME} #${env.BUILD_NUMBER}",
                 body: "Oops! The build failed. Please check."
        }
    }
}

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

The post section sends email notifications after the pipeline finishes.

If the build succeeds, it sends a success email to the team.

If the build fails, it sends a failure email to alert the team immediately.

Commands
This command starts the Jenkins pipeline named 'my-pipeline' to run the build and test stages.
Terminal
jenkins-cli build my-pipeline
Expected OutputExpected
Started build #15 Waiting for build to complete... Finished: SUCCESS
This command fetches the console output of build number 15 to check the build logs and confirm notifications were triggered.
Terminal
jenkins-cli console my-pipeline 15
Expected OutputExpected
[Pipeline] Start of Pipeline [Pipeline] echo Building... [Pipeline] echo Testing... [Pipeline] mail Sending email to team@example.com [Pipeline] End of Pipeline Finished: SUCCESS
Key Concept

If you remember nothing else from this pattern, remember: notifications keep the team informed instantly so problems get fixed faster and successes are celebrated.

Common Mistakes
Not configuring notifications in the Jenkinsfile post section
Without this, the team won't get alerts and may miss build failures or successes.
Always add a post section with success and failure blocks that send notifications.
Using incorrect email addresses or missing mail server setup
Emails won't be sent if Jenkins can't connect to a mail server or the address is wrong.
Configure Jenkins mail server settings correctly and verify recipient emails.
Summary
Use the Jenkinsfile post section to send notifications after builds.
Run the pipeline with jenkins-cli to trigger builds and notifications.
Check console output to verify notifications were sent.