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.
pipeline {
agent any
stages {
stage('Post build Actions') {
steps {
echo "hi my name is sandeep"
}
}
}
post {
success {
echo "This is post build success"
}
}
}
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.
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.
Hands-on live training, real projects, and placement support — become job-ready in DevOps.
Enroll in DevOps Training →