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

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • None
    •  lockable-resources 2.2

      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

          [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

          Brandon Saunders created issue -
          Brandon Saunders made changes -
          Description Original: 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

           

          {{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
          {color:#ff0000}[p3] C null{color}
          [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?
          New: 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 ACCOUNTS_VAR 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
           {color:#ff0000}[p3] C null{color}
           [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?
          Brandon Saunders made changes -
          Description Original: 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 ACCOUNTS_VAR 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
           {color:#ff0000}[p3] C null{color}
           [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?
          New: 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
           {color:#ff0000}[p3] C null{color}
           [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?
          Brandon Saunders made changes -
          Summary Original: Locked resources using the variable parameter do not get set to the variable once released to another requester New: 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
          Brandon Saunders made changes -
          Description Original: 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
           {color:#ff0000}[p3] C null{color}
           [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?
          New: 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
           {color:#ff0000}[p3] C null{color}
           [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

          Tom Skrainar added a comment -

          Observing the same issue as well.

          Tom Skrainar added a comment - Observing the same issue as well.

          Jan Kacik added a comment -

          We are experiencing the same issue. When you try to lock a resource and it has to wait in the queue for some time, then it will get null in the variable.

          Jan Kacik added a comment - We are experiencing the same issue. When you try to lock a resource and it has to wait in the queue for some time, then it will get null in the variable.

          Jeroen Bogers added a comment - - edited

          It seems that if the lock can be immediately granted, the variable is set. If waiting on the resource is needed it is not set.
          I suspect the error is on line 51 of src/main/java/org/jenkins/plugins/lockableresources/LockStepExecution.java

          The code there states:

           		LockableResourcesStruct resourceHolder = new LockableResourcesStruct(resources, step.label, step.quantity);
          

          I think this should have been (in accordance with the added LockableResourcesStruct on line 56 of src/main/java/org/jenkins/plugins/lockableresources/queue/LockableResourcesStruct.java):

           		LockableResourcesStruct resourceHolder = new LockableResourcesStruct(resources, step.label, step.quantity, step.variable);
          

          This is because if the lock is queued instead of granting the lock directly (with the variable as part of the 'lock' call, the resourceHolder is put on the queue.
          When the lock is then granted the variable name is looked up in the LockableResourcesStruct but it is not set and thus the environment variable will not be set.

          EDIT: A PR was already created by 'boblloyd' to fix this issue: https://github.com/jenkinsci/lockable-resources-plugin/pull/95

          Jeroen Bogers added a comment - - edited It seems that if the lock can be immediately granted, the variable is set. If waiting on the resource is needed it is not set. I suspect the error is on line 51 of src/main/java/org/jenkins/plugins/lockableresources/LockStepExecution.java The code there states: LockableResourcesStruct resourceHolder = new LockableResourcesStruct(resources, step.label, step.quantity); I think this should have been (in accordance with the added LockableResourcesStruct on line 56 of src/main/java/org/jenkins/plugins/lockableresources/queue/LockableResourcesStruct.java): LockableResourcesStruct resourceHolder = new LockableResourcesStruct(resources, step.label, step.quantity, step.variable); This is because if the lock is queued instead of granting the lock directly (with the variable as part of the 'lock' call, the resourceHolder is put on the queue. When the lock is then granted the variable name is looked up in the LockableResourcesStruct but it is not set and thus the environment variable will not be set. EDIT: A PR was already created by 'boblloyd' to fix this issue: https://github.com/jenkinsci/lockable-resources-plugin/pull/95
          Jeroen Bogers made changes -
          Link New: This issue is related to JENKINS-40997 [ JENKINS-40997 ]
          Jeroen Bogers made changes -
          Remote Link New: This issue links to "PR #95 (Web Link)" [ 20293 ]

            tgr Tobias Gruetzmacher
            avidviewer Brandon Saunders
            Votes:
            26 Vote for this issue
            Watchers:
            28 Start watching this issue

              Created:
              Updated:
              Resolved: