I have a Jenkins pipeline which has multiple stages, for example:
node(\"nodename\") {
stage(\"Checkout\") {
git ....
}
stage(\"Check Preconditions
I handled in a declarative way as shown below:
Based on catchError block it will execute post block. If post result falls under failure category, the error block will be executed to stop upcoming stages like Production, PreProd etc.
pipeline {
agent any
stages {
stage('Build') {
steps {
catchError {
sh '/bin/bash path/To/Filename.sh'
}
}
post {
success {
echo 'Build stage successful'
}
failure {
echo 'Compile stage failed'
error('Build is aborted due to failure of build stage')
}
}
}
stage('Production') {
steps {
sh '/bin/bash path/To/Filename.sh'
}
}
}
}