Disable a stage in Jenkinsfile

Viewed 6514

I want to temporary disable some stages in Jenkinsfile. Removing them and then restoring from version history seems like too much hasssle. I tried adding this:

    stage('Tests') {
      when {
        false
      }
    (...)

But results in an error when I trigger the job:

WorkflowScript: 30: Expected a when condition @ line 30, column 7.

         when {

         ^

WorkflowScript: 30: Empty when closure, remove the property or add some content. @ line 30, column 7.

         when {

Is there a way to do when: never in Jenkins declarative pipelines?

1 Answers

You can evaluate a boolean expression to disable the stage. Furthermore you could simply remove the stage or comment it out.

 stage('Tests') {
      when {
        expression { false }
      }
    ...
Related