We can mention some test conditions to run post the completion of stages in a pipeline.
Here's the code snippet:
post {
always {
echo “This block runs always !!!”
}
success {
echo “This block runs when the stages has a success status”
}
unstable {
echo “This block is run when the stages abort with an unstable status”
}
}
Here are the post conditions reserved for jenkinsfile:
always: Run the steps in the post section regardless of the completion status of the Pipeline’s or stage’s run.
unstable: Only run the steps in post if the current Pipeline’s or stage’s run has an "unstable" status, usually caused by test failures, code violations, etc.
aborted: Only run the steps in post if the current Pipeline’s or stage’s run has an “aborted” status.
success: Only run the steps in post if the current Pipeline’s or stage’s run has a "success" status.
failure: Only run the steps in post if the current Pipeline’s or stage’s run has a "failed" status.
changed: Only run the steps in post if the current Pipeline’s or stage’s run has a different completion status from its previous run.
cleanup: Run the steps in this post condition after every other post condition has been evaluated, regardless of the Pipeline or stage’s status.