0
0
Jenkinsdevops~10 mins

Post section (success, failure, always) in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Post section (success, failure, always)
Start Pipeline
Run Build Steps
Check Build Result
Post Success
End Pipeline
The pipeline runs build steps, then checks the result. Depending on success, failure, or always, it runs the matching post actions.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { sh 'exit 0' }
    }
  }
  post {
    success { echo 'Build succeeded' }
    failure { echo 'Build failed' }
    always { echo 'Cleanup' }
  }
}
This Jenkins pipeline runs a build stage that succeeds, then runs post steps for success and always.
Process Table
StepBuild ResultPost Condition CheckedPost Action ExecutedOutput
1RunningN/AN/ABuild stage starts
2Successsuccessecho 'Build succeeded'Build succeeded
3SuccessfailureNo action
4Successalwaysecho 'Cleanup'Cleanup
5EndN/AN/APipeline ends
💡 Build succeeded, so success and always post sections run; failure section skipped.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
buildResultnullrunningsuccesssuccesssuccesssuccess
Key Moments - 2 Insights
Why does the failure post section not run when the build succeeds?
Because the post section 'failure' only runs if the build result is failure. As shown in execution_table row 3, the buildResult is 'success', so failure actions are skipped.
Does the always post section run regardless of build result?
Yes, the 'always' post section runs no matter what. In execution_table row 4, even after success, the always action runs.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the buildResult at Step 2?
Arunning
Bsuccess
Cfailure
Dnull
💡 Hint
Check the 'Build Result' column at Step 2 in the execution_table.
At which step does the failure post section get checked?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'Post Condition Checked' column in the execution_table.
If the build failed, which post sections would run?
Afailure and always
Bsuccess and always
Conly failure
Donly always
💡 Hint
Remember 'always' runs no matter what, and 'failure' runs only on failure.
Concept Snapshot
Jenkins post section runs after stages finish.
Use 'success' for actions on success.
Use 'failure' for actions on failure.
Use 'always' for actions that run every time.
Only matching post blocks run based on build result.
Full Transcript
This Jenkins pipeline example shows how the post section works. After the build stage runs and succeeds, Jenkins checks the build result. It runs the 'success' post block because the build succeeded. It skips the 'failure' block because the build did not fail. It always runs the 'always' block regardless of result. The execution table traces these steps clearly. Variables track the build result changing from null to running to success. Key moments clarify why failure block does not run on success and that always block runs every time. The quiz tests understanding of these steps. The snapshot summarizes the post section usage simply.