#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
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 →