In a Jenkins scripted pipeline with the below structure, the return
command will exit only the withEnv
.
node{
withEnv([...]){
stage('1'){
...
}
stage('2'){
.....
}
if( env.BRANCH_NAME != 'master' ) {
currentBuild.result = 'SUCCESS'
return
}
stage('3'){
...
}
}
stage('4'){
withEnv([...]){
...
}
}
stage('5'){
...
}
stage('6'){
...
}
}
How can I stop the entire pipeline after stage2 with SUCCESS?