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

Ability to leave Declarative node block w/ top-level agent for a single stage

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • pipeline-model-definition 0.8.1

      I have a use case where I'd like to have a specific section of the pipeline limited to one concurrent step across all pipeline instances.

      Jenkinsfile
      pipeline {
        agent {
          docker {
            label 'label'
            image 'image'
          }
        }
      
        stages { 
          stage('locked_staged') {
            steps {
              //do some work
              lock(resource: 'resource', inversePrecedence:false) {
                //do locked work
              }
              //do more work
            }
          }
          
          stage('unlocked_stage') {
            steps {
              //work
            }
          }
      }
      

      This example would consume a node for the entire pipeline. Any node hitting the lock stage would current be blocked waiting on the lock. I would like for the node to be released once the lock is hit and resume once available.

      There is a partial workaround by specifically declaring agent at the appropriate stage.

      Jenkinsfile with workaround
      pipeline {
        agent none
      
        stages { 
           stage('locked_staged') {
              agent 'label'
              steps {
                lock(resource: 'resource', inversePrecedence:false) {
                  //do some work
                }
             }
          }
          
          stage('unlocked_stage') {
            steps {
              //work
            }
          }
      }
      

          [JENKINS-40966] Ability to leave Declarative node block w/ top-level agent for a single stage

            Unassigned Unassigned
            rpocase Robby Pocase
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: