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

Block of stages functioning as a concurrency unit

      Sometimes it is desirable to mark several stage boundaries in a build even though from the perspective of the concurrency semantics they are logically a single stage. This would require a new option to the stage step. Thus

      stage 'build'
      ...
      stage name: 'deploy', concurrency: 1
      ...
      stage name: 'test', labelOnly: true
      ...
      

      would behave exactly like

      stage 'build'
      ...
      stage name: 'deployAndTest', concurrency: 1
      ...
      

      other than the labeling via StageAction. In other words, with labelOnly set, the execution would run this part but then return true to avoid interaction with the concurrency system.

      Alternately there could be a block-scoped variant of the step

      stageBlock('build') {
        ...
      }
      stageBlock(name: 'deployAndTest', concurrency: 1) {
        stageBlock('deploy') {
          ...
        }
        stageBlock('test') {
          ...
        }
      }
      

      where concurrency would have the same meaning as in stage except that "entering" and "exiting" would refer to the block scope rather than a standalone step. This would overlap somewhat with JENKINS-26107 and might be a good stepping stone to a parallel-aware stage that blocks only within the given branch of various builds. The downside is that blocks must nest, which could be a problem if you wanted finer control over node allocation and so on.

          [JENKINS-29892] Block of stages functioning as a concurrency unit

          I think a better approach is to design a separate primitive that just handles the mutual exclusion.

          Say something like:

          def uatAccess = criticalSection(concurrency:2)
          ...
          uatAccess {
             sh 'deploy to UAT'
          }
          ...
          uatAcccess {
             sh 'do something else with UAT'
          }
          

          with a short hand like the following for the common case where there's only one use of mutual exclusion block:

          criticalSection(concurrency:2) {
             ...
          }
          

          Kohsuke Kawaguchi added a comment - I think a better approach is to design a separate primitive that just handles the mutual exclusion. Say something like: def uatAccess = criticalSection(concurrency:2) ... uatAccess { sh 'deploy to UAT' } ... uatAcccess { sh ' do something else with UAT' } with a short hand like the following for the common case where there's only one use of mutual exclusion block: criticalSection(concurrency:2) { ... }

          Jesse Glick added a comment -

          That is already filed as JENKINS-30269.

          Jesse Glick added a comment - That is already filed as JENKINS-30269 .

          Jesse Glick added a comment -

          Probably will not fix, as we plan to deprecate concurrency-related features of stage.

          Jesse Glick added a comment - Probably will not fix, as we plan to deprecate concurrency-related features of stage .

          Andrew Bayer added a comment -

          jglick Seems like this should probably be closed, since milestone and lock are basically the answer to this?

          Andrew Bayer added a comment - jglick Seems like this should probably be closed, since milestone and lock are basically the answer to this?

          Jesse Glick added a comment -

          Right.

          Jesse Glick added a comment - Right.

            jglick Jesse Glick
            jglick Jesse Glick
            Votes:
            4 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: