Uncodemy Logo ← Back to Course
Jenkins · Topic 15 of 15

Post-Build Actions in Pipeline

What is a Post-Build Action?

A Jenkins Post-Build action is a task executed after the build has completed. When you don't want to care whether a build stage succeeded or failed, but you still want something to run automatically afterward, you use post-build actions.

Post Conditions

  1. always — runs regardless of the build result.
  2. success — runs only when the stage build succeeds.
  3. failure — runs only when the stage build fails.

Success Example

pipeline {
    agent any
    stages {
        stage('Post build Actions') {
            steps {
                echo "hi my name is sandeep"
            }
        }
    }
    post {
        success {
            echo "This is post build success"
        }
    }
}

Failure Example

pipeline {
    agent any
    stages {
        stage('Post build Actions') {
            steps {
                eco "hi my name is sandeep"   // intentionally invalid command
            }
        }
    }
    post {
        failure {
            echo "This is post build failure"
        }
    }
}

Since eco is not a valid command, the stage fails — and the failure block automatically prints its message.

Always Example

pipeline {
    agent any
    stages {
        stage('Post build Actions Success') {
            steps { echo "hi this is sandy" }
        }
        stage('Post build Actions') {
            steps { eco "hi my name is sandeep" }
        }
    }
    post {
        always {
            echo "This is post build always"
        }
    }
}

No matter if the stages above succeed or fail, the always block executes every single time — useful for cleanup steps, notifications, or logging.

Master Jenkins & DevOps with Uncodemy

Hands-on live training, real projects, and placement support — become job-ready in DevOps.

Enroll in DevOps Training →