Course contentsShow
← Cloud and Infrastructure
Lesson 1790 of 2,98937. JenkinsFree lesson

Post Actions and Notifications

Define post-build actions for success, failure, or always conditions to send notifications and cleanup.

Post Actions and Notifications

What you'll learn: How to define cleanup tasks and send build status notifications using Jenkins Pipeline post-build actions.

After your pipeline stages execute, you often need to perform cleanup, send notifications, or archive results—regardless of whether the build succeeded or failed. Jenkins provides post actions that run based on specific build conditions, letting you respond appropriately to different outcomes.

Understanding Post Blocks

Think of post actions like the "finally" block in exception handling: they always run after your main code, but you can also branch logic based on what happened. In Jenkins, the post section contains conditional blocks that execute cleanup and notification tasks.

Post Condition Types

Jenkins offers several condition keywords:

  • always — Runs no matter what (cleanup, archiving)
  • success — Only when the build succeeds
  • failure — Only when the build fails
  • unstable — When tests fail but build completes
  • changed — When status differs from previous build

These conditions let you send targeted notifications—congratulating the team on success, alerting on failure, or cleaning up temporary files regardless of outcome.

Common Use Cases

Notifications: Send email, Slack messages, or webhook calls to inform teams about build status. You might notify everyone on failure but only post success messages to a dedicated channel.

Cleanup: Delete temporary files, stop test containers, or free workspace resources. This prevents disk space issues and keeps agents healthy.

Artifact Management: Archive logs, test results, or build artifacts only when specific conditions are met.

Practical Example Pattern

Structure your post section at the pipeline or stage level. Use always for mandatory cleanup, success for celebration notifications, and failure for urgent alerts. You can nest multiple actions under each condition, and they execute in order.

Key Takeaway: Post actions let you respond to build outcomes with condition-specific tasks like notifications and cleanup, ensuring your pipeline handles success and failure gracefully while maintaining system hygiene.