Loading

Quipoin Menu

Learn • Practice • Grow

jenkins / Post Actions
tutorial

Post Actions

The post section defines actions that run after the pipeline (or a stage) completes, regardless of success or failure. It’s ideal for cleanup, notifications, and reporting.

Post Conditions

In Declarative Pipeline, post supports several conditions:
  • always: Runs no matter the outcome.
  • success: Runs only if pipeline succeeded.
  • failure: Runs only if pipeline failed.
  • aborted: Runs if pipeline was manually aborted.
  • unstable: Runs if pipeline is unstable (e.g., test failures but build not broken).
  • changed: Runs if pipeline result is different from previous run.
Example:
pipeline {
agent any
stages {
stage('Test') {
steps { sh 'make test' }
}
}
post {
always {
echo 'Pipeline finished'
}
success {
echo 'All tests passed!'
}
failure {
echo 'Tests failed. Check logs.'
}
}
}

Stage‑Level Post

You can also use post inside a stage:
stage('Deploy') {
steps { ... }
post {
success { echo 'Deployment succeeded' }
failure { echo 'Deployment failed' }
}
}

Common Post Actions

  • Send email/Slack notifications.
  • Clean up workspace (deleteDir()).
  • Archive artifacts (archiveArtifacts).
  • Publish test reports (junit).
  • Trigger another job (build).

Scripted Pipeline Equivalent

In Scripted, use try/catch/finally:
node {
try {
stage('Build') { ... }
} catch (e) {
echo 'Failure'
currentBuild.result = 'FAILURE'
} finally {
echo 'Always runs'
}
}


Two Minute Drill
  • post runs actions after pipeline/stage completion.
  • Conditions: always, success, failure, aborted, unstable, changed.
  • Use for notifications, cleanup, and reporting.
  • In Scripted, use try/catch/finally.

Need more clarification?

Drop us an email at career@quipoinfotech.com