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

Stage "when" should have "stage" condition

XMLWordPrintable

      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' }
              }
          }
      }
      

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

              Created:
              Updated: