'Jenkinsfile - a way to skip the whole pipeline?

I use the declarative syntax for developing the (multibranch) pipeline script and I'm looking for a way to skip the whole pipeline based on some condition, without having to modify the when on every single stage.

Current use case: I'm setting up a cron to trigger builds at night, but I only want let's say the branches release/v1 and develop to go through the pipeline at night, not the dozen of other branches.

triggers {
  cron('H 21 * * 1-5')
}

// SKIP PIPELINE if triggered by timer AND branch not 'release/v1' OR 'develop'

stages {
  stage('build') {
    when { ... }
  }
  stage('UT') {
    when { ... }
  }
etc...
}

any hints would be appreciated.



Solution 1:[1]

You can use the SCM Skip plugin. Then use it in the pipeline like so:

scmSkip(deleteBuild: true, skipPattern:'.*#skip-ci.*')

This also enables to delete the build and also use a regex expression easily. The problem is, it aborts the next builds, and then ignores them for the relevant PR if you're connected with GitHub organization.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1