stage ("Publish CF app") {
environment {
JENKINSBOT = credentials('...')
}
when {
branch "develop"
}
steps {
script {
STAGE_NAME = "Publish CF app"
}
// Login and push
sh "cf api ..."
sh "cf login ... -u $JENKINSBOT_USR -p $JENKINSBOT_PSW"
sh "cf push"
slackSend (
color: '#199515',
message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER> passed successfully."
)
}
}
You could also use the POST directive inside a stage:
stage {
steps {
...
}
post {
success {
slack...
}
failure {
slack...
}
}
}
Now, once a stage fails, the whole job fails, so you don't really need to handle the failure in each stage. Instead you can also use POST globally:
And as you can see in my first example, I basically set a "STAGE_NAME" in each stage and use it in the failure directive globally
stages {
stage {
steps {
}
}
stage {
steps {
}
}
post {
success {
}
failure {
slackSend ( color: '#F01717',
message: "$JOB_NAME: <$BUILD_URL|Build #$BUILD_NUMBER>, '$STAGE_NAME' stage failed."
)
}
}
}