I am trying to add try catch block in Jenkins declarative pipeline but I end up with the following error, I read the document on adding try catch block for scripted pipeline syntax of Jenkins(https://jenkins.io/doc/book/pipeline/syntax/#post-conditions) but I didn't get anything on declarative syntax.
pipeline {
agent any
stages {
try {
stage('Checkout') {
steps {
script {
if (ci_branches.contains(env.BRANCH_NAME)) {
// Pull the code from bitbucket repository
checkout scm
}
}
}
}
}
catch(all) {
currentBuild.result='FAILURE'
}
}
}
Jenkins ci build result
[Bitbucket] Build result notified
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 36: Expected a stage @ line 36, column 13.
try {
^
WorkflowScript: 35: No stages specified @ line 35, column 9.
stages {
^