Mutually exclusive stages in declarative pipeline

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      There have been a few cases where I've needed to define a set of mutually exclusive stages of which only one should execute. Right now this can be accomplished with a parallel block containing stages with inter-related when conditions, but this is annoying to manage. I propose adding a new switch block to stage.

       

      stage ("Do It") {
          switch {
              stage("Stage A") {
                  when { expression { return conditionA } }
                  steps { ... }
              }
              stage("Stage B") {
                   when { expression { return conditionB } }
                   steps { ... }
              }
              stage("Stage C") {
                  steps { ... }
              }
          }
      }
      

      This means "If condition A, do Stage A. Else if condition B, do Stage B. Else, do Stage C." switch would be at the same level as stages, parallel, and matrix today. This allows Blue Ocean to clearly display the mutually exclusive stages (probably in a vertical arrangement, like it does for parallel).

            Assignee:
            Liam Newman
            Reporter:
            Jesse Rittner
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: