Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-37781

Pipeline Config: ability to skip whole pipeline or stages based on boolean condition

      A common enough pattern is to skip either a whole pipeline or a stage based on the branch of execution. This is pretty common in deployment focused pipelines, and would be a strong reason to break out of config and that would be a shame.

      It would be nice if this was somewhat first class in pipeline config. Some may be able to be done with a block scoped step... but not clear if all can be.

      A general way of saying "if this boolean condition is false, skip this stage" would be the way to go - a branch matching would be one particular use of this, but the right thing to do is go generic.

          [JENKINS-37781] Pipeline Config: ability to skip whole pipeline or stages based on boolean condition

          Andrew Bayer created issue -
          Andrew Bayer made changes -
          Description Original: A common enough pattern is to skip either a whole pipeline or a stage based on the branch of execution. This is pretty common in deployment focussed pipelines, and would be a strong reason to break out of config and that would be a shame.

          It would be nice if this was somewhat first class in pipeline config. Some may be able to be done with a block scoped step... but not clear if all can be.

          In scope:

          * on-branch declaration as a peer with postBuild or stages
          * same on-branch pattern per stage
          New: A common enough pattern is to skip either a whole pipeline or a stage based on the branch of execution. This is pretty common in deployment focused pipelines, and would be a strong reason to break out of config and that would be a shame.

          It would be nice if this was somewhat first class in pipeline config. Some may be able to be done with a block scoped step... but not clear if all can be.

          A general way of saying "if this boolean condition is false, skip this stage" would be the way to go - a branch matching would be one particular use of this, but the right thing to do is go generic.

          Summary Original: Pipeline Config: ability to skip whole pipeline or stages based on branch New: Pipeline Config: ability to skip whole pipeline or stages based on boolean condition

          Anton Piatek added a comment -

          It is easy enough to skip a stage with an if block, but then the view of that pipeline gets cleared every time the number of stages changes. It would be nice to report a stage as N/A or skipped, and perhaps have it coloured white to show clearly that it wasn't actually run during this particular build.

          Anton Piatek added a comment - It is easy enough to skip a stage with an if block, but then the view of that pipeline gets cleared every time the number of stages changes. It would be nice to report a stage as N/A or skipped, and perhaps have it coloured white to show clearly that it wasn't actually run during this particular build.
          Andrew Bayer made changes -
          Assignee Original: Andrew Bayer [ abayer ] New: rsandell [ rsandell ]

          Patrick Wolf added a comment -

          jamesdumay michaelneale How would this affect Blue Ocean display?

          Patrick Wolf added a comment - jamesdumay michaelneale How would this affect Blue Ocean display?

          Andrew Bayer added a comment -

          Well, we'd still "run" the stage - we just wouldn't actually do anything in it, like we now do with stages after a failed stage, so that we preserve the execution plan regardless of status.

          Andrew Bayer added a comment - Well, we'd still "run" the stage - we just wouldn't actually do anything in it, like we now do with stages after a failed stage, so that we preserve the execution plan regardless of status.

          Patrick Wolf added a comment -

          As pointed out above by Anton, showing it as "Successful", "Failed", or "Unstable" wouldn't be entirely accurate.

          Also, would this skip the "post" actions entirely as well?

          Patrick Wolf added a comment - As pointed out above by Anton, showing it as "Successful", "Failed", or "Unstable" wouldn't be entirely accurate. Also, would this skip the "post" actions entirely as well?

          Andrew Bayer added a comment -

          As of now, there's no way to set a stage to a specific status, so it'll just be whatever the overall status is.

          I'd say yes, we would skip post-stage actions as well.

          Andrew Bayer added a comment - As of now, there's no way to set a stage to a specific status, so it'll just be whatever the overall status is. I'd say yes, we would skip post-stage actions as well.

          James Dumay added a comment - - edited

          hrmpw abayer what if "skipped" stages were not displayed at all? However, if we did want skipped stages to show we should introduce a skipped state.

          James Dumay added a comment - - edited hrmpw abayer what if "skipped" stages were not displayed at all? However, if we did want skipped stages to show we should introduce a skipped state.

          Code changed in jenkins
          User: Robert Sandell
          Path:
          pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTScriptBlock.java
          pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTStage.java
          pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTWhen.java
          pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidator.java
          pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy
          pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy
          pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy
          pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy
          pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy
          pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java
          pipeline-model-definition/src/test/resources/simpleWhen.groovy
          http://jenkins-ci.org/commit/pipeline-model-definition-plugin/dfab9e247559bf258b0aa35e4160cc91b45e0abc
          Log:
          JENKINS-37781 Adding Stage.when to specify if a stage should run or not

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTScriptBlock.java pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTStage.java pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/ast/ModelASTWhen.java pipeline-model-api/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidator.java pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/model/Stage.groovy pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/JSONParser.groovy pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/parser/ModelParser.groovy pipeline-model-definition/src/main/groovy/org/jenkinsci/plugins/pipeline/modeldefinition/validator/ModelValidatorImpl.groovy pipeline-model-definition/src/main/resources/org/jenkinsci/plugins/pipeline/modeldefinition/ModelInterpreter.groovy pipeline-model-definition/src/test/java/org/jenkinsci/plugins/pipeline/modeldefinition/WhenStageTest.java pipeline-model-definition/src/test/resources/simpleWhen.groovy http://jenkins-ci.org/commit/pipeline-model-definition-plugin/dfab9e247559bf258b0aa35e4160cc91b45e0abc Log: JENKINS-37781 Adding Stage.when to specify if a stage should run or not

            rsandell rsandell
            abayer Andrew Bayer
            Votes:
            3 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved: