How to skip Stages in jenkins

Jenkins 1.x and 2.x offer 2 differnt views to the same issue. in jenkins 1.x you only had the jenksin view plugin. so you just write your work jenkisn pipeline and skip the stages.

for this case you have

import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
// .....
stage('I am skipped') {
    Utils.markStageSkippedForConditional(STAGE_NAME)
}

for jenkins 2.X you have the blueocean view which has conditions for skipped steps. so to skip a sage you simply have to wrap the stage in a "when" condition

stage('My Conditional Stage') {
    when {
        branch 'master'
    }
    steps {
        echo 'Do that only on master branch'
    }
}

Related Article