Problem Statement
What are post conditions in Jenkins Pipeline?
Explanation
Post sections define actions to run after pipeline or stage completion based on build result. Post conditions include always (always run), success (only if successful), failure (only if failed), unstable (tests failed but build passed), changed (status changed from previous run), fixed (previous build failed, this succeeded), regression (previous build succeeded, this failed), aborted (user aborted), unsuccessful (not successful), and cleanup (runs after all other conditions).
Example:
```groovy
post {
success {
echo 'Build succeeded!'
slackSend color: 'good', message: 'Build successful'
}
failure {
echo 'Build failed!'
mail to: 'team@example.com',
subject: "Failed: ${env.JOB_NAME} #${env.BUILD_NUMBER}",
body: "Check console output at ${env.BUILD_URL}"
}
always {
junit '**/target/test-results/*.xml'
cleanWs()
}
}
```
Post sections can be defined at pipeline level (apply to entire pipeline) or stage level (apply to specific stage). Common uses include sending notifications, publishing test results, cleaning workspaces, archiving artifacts, and triggering downstream jobs. Understanding post actions enables proper cleanup, notification, and result handling regardless of build outcome.
