I have Jenkins pipeline which consists of 2 stages,
I want to execute second stage only on certain condition, e.g. if git branch is not master.
When it was on bash I used to use simple logic:
if [condition] {exit 0} else {stage2 function} fi
How is it possible in Jenkins pipeline groovy?
My Jenkinsfile looks like this -
pipeline {
agent any
stages {
stage ('First') {
steps {
echo "First"
}
if (env.BRANCH_NAME == 'master') {
echo 'First stage is enought, exit 0 shoul happened here'
currentBuild.result = 'SUCCESS'
return
} else {
echo 'Second stage must be executed'
}
}
stage('Second') {
steps {
echo "Second"
}
}
}
}
However, it works as expected in scripted pipeline - https://github.com/kagarlickij/jenkins-pipeline/blob/scripted/Jenkinsfile
steps
block. – Griffin