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

Stage "when" should have "stage" condition

    XMLWordPrintable

Details

    Description

      I'd like to create two stages, where if one runs the other doesn't - effectively and `if-else`.

      Right now I'd have to do something like this:

      stages {
          stage ('Full Build') {
              when {
                  expression { return params.FORCE_FULL_BUILD }
              }
          }
      
          stage ('Incremental Build') {
              when {
                  expression { return !params.FORCE_FULL_BUILD }
              }
          }
      }
      

      For simple expressions, that's no problem. For complex expressions it gets tiresome.

      The `when {}` block needs a way to indicate `else`. This could be done (when combined with a logical `not` condition) by have a `stage` condition. Like so:

      stages {
          stage ('Full Build') {
              when {
                  expression { return params.FORCE_FULL_BUILD }
              }
          }
      
          stage ('Incremental Build') {
              when {
                  not { stage 'Full Build' }
              }
          }
      }
      

      This would also allow for stages to depend on previous stages in a clear fashion. For example:

      stages {
          stage ('Full Build') {
              when {
                  expression { return params.FORCE_FULL_BUILD }
              }
          }
      
          stage ('Incremental Build') {
              when {
                  not { stage 'Full Build' }
              }
          }
      
          stage ('Full Tests') {
              when {
                  stage 'Full Build' }
              }
          }
      
          stage ('Incremental Tests') {
              when {
                  stage 'Incremental Build' }
              }
          }
      }
      

      Attachments

        Issue Links

          Activity

            bitwiseman Liam Newman created issue -
            bitwiseman Liam Newman made changes -
            Field Original Value New Value
            Link This issue relates to JENKINS-41185 [ JENKINS-41185 ]
            jamesdumay James Dumay made changes -
            Summary [Declarative Pipeline] Stage "when" should have "stage" condition Stage "when" should have "stage" condition
            jamesdumay James Dumay made changes -
            Epic Link JENKINS-45426 [ 183594 ]
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Remote Link This issue links to "new plugin repo (initial) (Web Link)" [ 17831 ]
            abayer Andrew Bayer made changes -
            Assignee Andrew Bayer [ abayer ]

            People

              Unassigned Unassigned
              bitwiseman Liam Newman
              Votes:
              11 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

                Created:
                Updated: