We are using the Script Pipeline syntax for our Jenkinsfile which has a lot of stage defined to build and deploy our code. We have a use case w
I also disliked the idea of having a redundant if{} block inside my stage{}. I solved this by overwriting the stage as follows
def stage(name, execute, block) {
return stage(name, execute ? block : {echo "skipped stage $name"})
}
now you can disable a stage as follows
stage('Full Build', false) {
...
}
Update You could also mark stage skipped using below def
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
def stage(name, execute, block) {
return stage(name, execute ? block : {
echo "skipped stage $name"
Utils.markStageSkippedForConditional(STAGE_NAME)
})
}