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

          Robby Pocase created issue -
          Andrew Bayer made changes -
          Description Original: 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.

          {code:java|title=Jenkinsfile}
          pipeline {
            agent {
              label 'label'
              docker '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
                }
              }
          }
          {code}

          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.

          {code:java|title=Jenkinsfile with workaround}
          pipeline {
            agent none

            stages {
              lock(resource: 'resource', inversePrecedence:false) {
                stage('locked_staged') {
                  agent 'label'
                  steps {
                    //do some work
                   }
                }
              }
              
              stage('unlocked_stage') {
                steps {
                  //work
                }
              }
          }
          {code}
          New: 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.

          {code:java|title=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
                }
              }
          }
          {code}

          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.

          {code:java|title=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
                }
              }
          }
          {code}
          Andrew Bayer made changes -
          Priority Original: Minor [ 4 ] New: Critical [ 2 ]
          Summary Original: Ability to lock portion of declarative pipeline without consuming node New: Ability to leave Declarative node block w/ top-level agent for a single stage
          James Dumay made changes -
          Epic Link New: JENKINS-45428 [ 183596 ]
          Andrew Bayer made changes -
          Priority Original: Critical [ 2 ] New: Major [ 3 ]
          Andrew Bayer made changes -
          Assignee Original: Andrew Bayer [ abayer ]

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

              Created:
              Updated: