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

[Declarative Pipeline] Stage "when" should have logical operator steps (and, or, not, all, any)

    Details

    • Similar Issues:

      Description

      The last change to the stage `when {}` block changed to using items like `branch` and `expression`.

      Multiple items cannot be used in the same when block. This makes sense because it would unclear whether those items should be "A or B", or if they should be "A and B".

      The `when` block should support logical blocks such as `and {}`, `or {}`, `not {}` to allow combining other conditions in a clear fashion.

      For example, when branch is master or parameter "FORCE_FULL_BUILD" is true:

      stage ('Build') {
          when {
              or {
                  branch 'master'
                  expression { return params.FORCE_FULL_BUILD }
              }
          }
      }
      

      Alternative: use `all {}` instead of `and`, and use `any {}` instead of `or {}`:

      stage ('Build') {
          when {
              any {
                  branch 'master'
                  expression { return params.FORCE_FULL_BUILD }
              }
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abayer Andrew Bayer
                Reporter:
                bitwiseman Liam Newman
              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: