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

Locked resources using the variable parameter do not get reset to the variable once released to another requester and only appear as null on subsequent locks

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      I'm appearing to hit an issue where a released resource does not get an update on the environment variable once the lock is released.  See the following code (with only two resources available in the automation-accounts label)

       

      node {
        parallel (
          "p1": {
            lock(label: 'automation-accounts', variable: 'ACCOUNTS_VAR', quantity: 1) {
              echo "A $env.ACCOUNTS_VAR"
              sleep 4
                   }
          },
          "p2": {
            lock(label: 'automation-accounts', variable: 'ACCOUNTS_VAR', quantity: 1) {
              echo "B $env.ACCOUNTS_VAR"
              sleep 2
                   }
          },
          "p3": {
            lock(label: 'automation-accounts', variable: 'ACCOUNTS_VAR', quantity: 1) {
              echo "C $env.ACCOUNTS_VAR"
                   }
               }
        )
      }

       

      In the log I get the following (note "C null"):
      [Pipeline] {
      [Pipeline] parallel
      [Pipeline] [p1] { (Branch: p1)
      [Pipeline] [p2] { (Branch: p2)
      [Pipeline] [p3] { (Branch: p3)
      [Pipeline] [p1] lock
      [p1] Trying to acquire lock on [Label: automation-accounts, Quantity: 1]
      [p1] Lock acquired on [Label: automation-accounts, Quantity: 1]
      [Pipeline] [p1] {
      [Pipeline] [p2] lock
      [p2] Trying to acquire lock on [Label: automation-accounts, Quantity: 1]
      [p2] Lock acquired on [Label: automation-accounts, Quantity: 1]
      [Pipeline] [p2] {
      [Pipeline] [p3] lock
      [p3] Trying to acquire lock on [Label: automation-accounts, Quantity: 1]
      [p3] Found 0 available resource(s). Waiting for correct amount: 1.
      [p3] [Label: automation-accounts, Quantity: 1] is locked, waiting...
      [Pipeline] [p1] echo
      [p1] A <Account1>
      [Pipeline] [p1] sleep
      [p1] Sleeping for 4 sec
      [Pipeline] [p2] echo
      [p2] B <Account2>
      [Pipeline] [p2] sleep
      [p2] Sleeping for 2 sec
      [p3] Lock acquired on [Label: automation-accounts, Quantity: 1]
      [Pipeline] [p2] }
      [p2] Lock released on resource [Label: automation-accounts, Quantity: 1]
      [Pipeline] [p3] {
      [Pipeline] [p2] // lock
      [Pipeline] [p2] }
      [Pipeline] [p3] echo
      [p3] C null
      [Pipeline] [p3] }
      [p3] Lock released on resource [Label: automation-accounts, Quantity: 1]
      [Pipeline] [p3] // lock
      [Pipeline] [p3] }
      [Pipeline] [p1] }
      [p1] Lock released on resource [Label: automation-accounts, Quantity: 1]
      [Pipeline] [p1] // lock
      [Pipeline] [p1] }
      [Pipeline] // parallel
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline

      Expected Result:
      I should get "C <Account2>

      Perhaps I'm calling it wrong though?  It appears that the lock is being acquired BEFORE the resource is released though this might be just a logging complication of calling it in parallel

        Attachments

          Issue Links

            Activity

            Hide
            vikashks vikash srivastava added a comment - - edited

            can somebody please clarify if the changes are merged to master?

            i still see below struct not updated with variable name.

             

            resourceHolderList.add(new LockableResourcesStruct(resources, resource.label, resource.quantity));

             

            my local changes.

             

            resourceHolderList.add(new LockableResourcesStruct(resources, resource.label, resource.quantity,step.variable,step.node));

            Show
            vikashks vikash srivastava added a comment - - edited can somebody please clarify if the changes are merged to master? i still see below struct not updated with variable name.   resourceHolderList.add(new LockableResourcesStruct(resources, resource.label, resource.quantity));   my local changes.   resourceHolderList.add(new LockableResourcesStruct(resources, resource.label, resource.quantity,step.variable,step.node));
            Hide
            inugunti Jagadeesh Inugunti added a comment - - edited

            Jeroen Bogers  We are still seeing this issue with lockable resource plugin 

             

            Please let us know if someone is working/looking into this issue , it will be really helpful if this gets resolved .

            Show
            inugunti Jagadeesh Inugunti added a comment - - edited Jeroen Bogers   We are still seeing this issue with lockable resource plugin    Please let us know if someone is working/looking into this issue , it will be really helpful if this gets resolved .
            Hide
            ryz Stefan Rystedt added a comment - - edited

            I have created PR#117 which should solve this issue. My way of solving it is a little bit cleaner according to my  opinion. But then I have not done any Jenkins plugin development until I did this fix. It can be merged as is thought.

            Show
            ryz Stefan Rystedt added a comment - - edited I have created PR#117 which should solve this issue. My way of solving it is a little bit cleaner according to my  opinion. But then I have not done any Jenkins plugin development until I did this fix. It can be merged as is thought.
            Hide
            stevenfoster Steven Foster added a comment -

            Stefan Rystedt's PR also fixes JENKINS-54541

            Show
            stevenfoster Steven Foster added a comment - Stefan Rystedt 's PR also fixes  JENKINS-54541
            Hide
            nwegner Niels Wegner added a comment -

            Steven Foster Thanks for that info. This will get us around stuck pipelines when freeing reservations

            Show
            nwegner Niels Wegner added a comment - Steven Foster Thanks for that info. This will get us around stuck pipelines when freeing reservations

              People

              • Assignee:
                Unassigned
                Reporter:
                avidviewer Brandon Saunders
              • Votes:
                23 Vote for this issue
                Watchers:
                24 Start watching this issue

                Dates

                • Created:
                  Updated: