How do I report the stage in which a declarative pipeline failed? In the fail block, I want to get failedStage.name and report it (eventually to slack).
pip
You can use a post directive in each stage, to act on failure with specific actions and notifications.
It's not exactly ideal as if you want that in all stages you'd have to repeat it though, and I don't think you can access your stage name dynamically, so it's really verbos and hard-coded. You could probably refactor that to use a library though.
pipeline {
agent { label 'master'}
stages {
stage('Ok') {
steps {
echo 'do thing'
}
post {
failure {
echo 'FAILED (in stage OK - should not happen :))'
}
}
}
stage('NotOK') {
steps {
sh 'make fail'
}
post {
failure {
echo 'FAILED (in stage NotOK)'
}
}
}
}
post {
always {
echo 'COMPLETED (global)'
}
failure {
echo 'FAILED (global)'
}
}
}