0
0
Jenkinsdevops~10 mins

Post-build actions in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Post-build actions
Build completes
Check post-build actions configured?
NoEnd
Yes
Execute post-build action 1
Execute post-build action 2
All post-build actions done
End
After the build finishes, Jenkins checks if any post-build actions are set and runs them one by one before ending the job.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Build') {
      steps { echo 'Building...' }
    }
  }
  post {
    success { echo 'Build succeeded!' }
    failure { echo 'Build failed!' }
  }
}
This Jenkins pipeline runs a build stage and then runs post-build actions depending on success or failure.
Process Table
StepBuild StatusPost-build Action CheckedAction ExecutedOutput
1Build runningNoNoneBuilding...
2Build succeededYessuccess blockBuild succeeded!
3Post-build actions completeN/AN/AJob ends
💡 All configured post-build actions executed after build success, job ends
Status Tracker
VariableStartAfter BuildAfter Post-buildFinal
buildStatusnullrunningsucceededsucceeded
postBuildActionnonenonesuccess block executedsuccess block executed
Key Moments - 2 Insights
Why does Jenkins run post-build actions only after the build finishes?
Because post-build actions depend on the build result, Jenkins waits until the build completes (see execution_table step 2) before running them.
What happens if no post-build actions are configured?
Jenkins skips post-build steps and ends the job immediately after the build (see concept_flow branch 'No').
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the build status at step 2?
ABuild running
BBuild failed
CBuild succeeded
DBuild not started
💡 Hint
Check the 'Build Status' column at step 2 in the execution_table
At which step does Jenkins execute the post-build success action?
AStep 2
BStep 3
CStep 1
DNo post-build action executed
💡 Hint
Look at the 'Action Executed' column in the execution_table
If the build failed, which post-build action would run instead?
Asuccess block
Bfailure block
Cno action
Dboth success and failure blocks
💡 Hint
Refer to the pipeline code in execution_sample under 'post' section
Concept Snapshot
Post-build actions run after the build finishes.
They depend on build status (success, failure).
Configured in Jenkins pipeline 'post' section.
Executed sequentially before job ends.
If none configured, job ends after build.
Full Transcript
In Jenkins, post-build actions are steps that run after the main build completes. The flow starts with the build running. Once the build finishes, Jenkins checks if any post-build actions are configured. If yes, it executes them one by one depending on the build result, such as running a success message if the build succeeded or a failure message if it failed. If no post-build actions are set, Jenkins ends the job immediately after the build. The example pipeline shows a build stage followed by post-build actions that print messages based on success or failure. The execution table traces the build running, then post-build success action running, then job ending. Variables like buildStatus and postBuildAction change accordingly. Common confusions include why post-build actions wait for build completion and what happens if none are configured. The quiz tests understanding of build status at steps, when post-build actions run, and which actions run on failure. The snapshot summarizes that post-build actions run after build, depend on status, and are configured in the pipeline's post section.