[JIRA] (JENKINS-56408) Lockable resources plugin doesn't assign resource if an env variable is used as label

9 views
Skip to first unread message

akansh.tayal@gmail.com (JIRA)

unread,
Mar 5, 2019, 4:08:02 AM3/5/19
to jenkinsc...@googlegroups.com
Akansh Tayal created an issue
 
Jenkins / Bug JENKINS-56408
Lockable resources plugin doesn't assign resource if an env variable is used as label
Issue Type: Bug Bug
Assignee: Unassigned
Components: lockable-resources-plugin
Created: 2019-03-05 09:07
Priority: Minor Minor
Reporter: Akansh Tayal

Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck infinitely waiting for the resource even though env variable is set.

 

stage("Setup")

{    env.NODE_LABEL = "pre_commit" }

stage ("Build") {

  options {
    lock(label: "${env.NODE_LABEL}", variable: "NODELABEL", quantity: 1)
  }

  sh "echo \"${env.NODELABEL}\""

}

}

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

akansh.tayal@gmail.com (JIRA)

unread,
Mar 5, 2019, 4:21:02 AM3/5/19
to jenkinsc...@googlegroups.com
Akansh Tayal updated an issue
Change By: Akansh Tayal
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck infinitely waiting for the resource even though env variable is set.

 

pipeline {

agent {
  node \{ label 'centos_node' }
}
stages {
 
stage("Setup") {
    steps {
      script {
  
    env.NODE_LABEL = "pre_commit"
      }

  }
}

stage ("Build") {

 
  options {
    lock(label: "${env.NODE_LABEL}", variable: "NODELABEL", quantity: 1)
  }
  steps {
 
  script {
     
sh "echo \"${env.NODELABEL}\""
    }

   
}

}

}
}

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource.

akansh.tayal@gmail.com (JIRA)

unread,
Mar 5, 2019, 4:26:02 AM3/5/19
to jenkinsc...@googlegroups.com
Akansh Tayal updated an issue
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck infinitely waiting for the resource even though env variable is set.

 

pipeline {

agent
{

{
  node \ \ { label 'centos_node' }

}
stages {
  stage("Setup") {
    steps {
      script
{

{
        env.NODE_LABEL = "pre_commit"
      }

  }
}
stage ("Build") {

  options {
    lock(label: "${env.NODE_LABEL}", variable: "NODELABEL", quantity: 1)
  }
  steps {
    script {
      sh "echo \"${env.NODELABEL}\""
    }

   }

}

}
}

 

Console Output :
 
+refs/heads/master:refs/remotes/origin/master # timeout=10
Checking out Revision 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10
Commit message: "send slack for only master builds"
> git rev-list --no-walk 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10[Pipeline] nodeRunning on [codereview1.eng.nutanix.com|http://erdinger.eng.nutanix.com/computer/codereview1.eng.nutanix.com/] in /root/workspace/QA/test_lock[Pipeline] {[Pipeline] stage[Pipeline] { (Setup)[Pipeline] script[Pipeline] {[Pipeline] }[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Build)[Pipeline] lockTrying to acquire lock on [Label: null, Quantity: 1]
Found 0 available resource(s). Waiting for correct amount: 1.
[Label: null, Quantity: 1] is locked, waiting...
 

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource.

akansh.tayal@gmail.com (JIRA)

unread,
Mar 5, 2019, 4:27:02 AM3/5/19
to jenkinsc...@googlegroups.com
Akansh Tayal updated an issue
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck infinitely waiting for the resource even though env variable is set.

 

pipeline {

agent

{   node
\\

{ label 'centos_node' }

}
stages {
  stage("Setup") {
    steps {
      script

{         env.NODE_LABEL = "pre_commit"       }

  }
}
stage ("Build") {

  options {
    lock(label: "${env.NODE_LABEL}", variable: "NODELABEL", quantity: 1)
  }
  steps {
    script {
      sh "echo \"${env.NODELABEL}\""
    }

   }

}

}
}

 

* Console Output : *
 
+refs/heads/master:refs/remotes/origin/master # timeout=10
Checking out Revision 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10
Commit message: "send slack for only master builds"
> git rev-list --no-walk 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10[Pipeline] nodeRunning on [codereview1.eng.nutanix.com|http://erdinger.eng.nutanix.com/computer/codereview1.eng.nutanix.com/] in /root/workspace/QA/test_lock[Pipeline] {[Pipeline] stage[Pipeline] { (Setup)[Pipeline] script[Pipeline]
{[Pipeline] }

[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Build)[Pipeline] lockTrying to acquire lock on [Label: null, Quantity: 1]
Found 0 available resource(s). Waiting for correct amount: 1.
[Label: null, Quantity: 1] is locked, waiting...
 

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource.

akansh.tayal@gmail.com (JIRA)

unread,
Mar 5, 2019, 4:28:02 AM3/5/19
to jenkinsc...@googlegroups.com
Akansh Tayal updated an issue
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck infinitely waiting for the resource even though env variable is set.

 

pipeline {

agent

{   node



{ label 'centos_node' }

}
stages {
  stage("Setup") {
    steps {
      script

{         env.NODE_LABEL = "pre_commit"       }

  }
}
stage ("Build") {

  options {
    lock( * label: "${env.NODE_LABEL}" * , variable: "NODELABEL", quantity: 1)

  }
  steps {
    script {
      sh "echo \"${env.NODELABEL}\""
    }

   }

}

}
}

 

*Console Output :*

 
+refs/heads/master:refs/remotes/origin/master # timeout=10
Checking out Revision 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10
Commit message: "send slack for only master builds"
> git rev-list --no-walk 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10[Pipeline] nodeRunning on [codereview1.eng.nutanix.com|http://erdinger.eng.nutanix.com/computer/codereview1.eng.nutanix.com/] in /root/workspace/QA/test_lock[Pipeline] {[Pipeline] stage[Pipeline] { (Setup)[Pipeline] script[Pipeline]

{[Pipeline] }

[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Build)[Pipeline] lockTrying to acquire lock on [Label: null, Quantity: 1]
Found 0 available resource(s). Waiting for correct amount: 1.
* [Label: null, Quantity: 1] is locked, waiting... *
 

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource.

akansh.tayal@gmail.com (JIRA)

unread,
Mar 5, 2019, 5:17:02 AM3/5/19
to jenkinsc...@googlegroups.com
Akansh Tayal updated an issue
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck infinitely waiting for the resource even though env variable is set.

 

pipeline {

agent

{   node

{ label 'centos_node' }

}
stages {
  stage("Setup") {
    steps {
      script

{         env.NODE_LABEL = "pre_commit"       }

  }
}
stage ("Build") {

  options {
    lock(*label: "${env.NODE_LABEL}"*, variable: "NODELABEL", quantity: 1)

  }
  steps {
    script {
      sh "echo \"${env.NODELABEL}\""
    }

   }

}

}
}

 

*Console Output :*
 
+refs/heads/master:refs/remotes/origin/master # timeout=10
Checking out Revision 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10
Commit message: "send slack for only master builds"
> git rev-list --no-walk 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10[Pipeline] nodeRunning on [codereview1.eng.nutanix.com|http://erdinger.eng.nutanix.com/computer/codereview1.eng.nutanix.com/] in /root/workspace/QA/test_lock[Pipeline] {[Pipeline] stage[Pipeline] { (Setup)[Pipeline] script[Pipeline]

{[Pipeline] }

[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Build)[Pipeline] lockTrying to acquire lock on [Label: null, Quantity: 1]
Found 0 available resource(s). Waiting for correct amount: 1.
*[Label: null, Quantity: 1] is locked, waiting...*
 

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource as label value is coming as null .

jens.beier@edict.de (JIRA)

unread,
Sep 5, 2019, 11:03:02 AM9/5/19
to jenkinsc...@googlegroups.com
Jens Beier commented on Bug JENKINS-56408
 
Re: Lockable resources plugin doesn't assign resource if an env variable is used as label

Any news on this issue? I am having the same problem. (declarative mulitbranch pipeline, Jenkins Version 2.176, Lockable Resources Plugin 2.5)

I am trying to dynamically determine the name of the resource which should be locked in an pipeline step before locking the resource. 

As far as I understand the problem, this is not an issue of using an environment variable but a timing issue. The lockable resources plugin seems to determine the value/name of the resource/label to be locked at the beginning of the pipeline. If the value/name of the resource/label to be locked is created after the start of the pipeline and before executing the lock the value passed to the lockable resources plugin has no effect.

Here an example that shows the issue:

Pipeline:

def resourceName = 'resource1'
pipeline {
    agent any
    stages {
        stage('change resource') {
            steps {
                echo "resourceName before update: ${resourceName}"
                script{
                    resourceName = 'resource2'
                }
                echo "resourceName before update: ${resourceName}"
            }
        }
        stage('lock resource') {
            options {
                lock resource: "${resourceName}", variable: 'RESOURCE_NAME'
            }
            steps {
                echo "resourceName after lock: ${resourceName}"
                echo "env.RESOURCE_NAME after lock: ${env.RESOURCE_NAME}"
            }
        }
    }
}

Console Output:

[Pipeline] Start of Pipeline
[Pipeline] node
Running on BuildSlave
[Pipeline] {
[Pipeline] stage
[Pipeline] { (change resource)
[Pipeline] echo
resourceName before update: resource1
[Pipeline] script
[Pipeline] {
[Pipeline] }
[Pipeline] // script
[Pipeline] echo
resourceName before update: resource2
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (lock resource)
[Pipeline] lock
Trying to acquire lock on [resource1]
Lock acquired on [resource1]
[Pipeline] {
[Pipeline] echo
resourceName after lock: resource2
[Pipeline] echo
env.RESOURCE_NAME after lock: resource1
[Pipeline] }
Lock released on resource [resource1]
[Pipeline] // lock
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

 

Can you change the lockable resource plugin so that the name of the resource is determined when the plugin is executed and not at the beginning of the pipeline?

 

tobias-jenkins@23.gs (JIRA)

unread,
Oct 4, 2019, 8:37:04 PM10/4/19
to jenkinsc...@googlegroups.com
Tobias Gruetzmacher updated an issue
 
Change By: Tobias Gruetzmacher
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets struck stuck infinitely waiting for the resource even though env variable is set.

 
{code}
pipeline {

agent

{   node

{ label 'centos_node' }

}
stages {
  stage("Setup") {
    steps {
      script

{         env.NODE_LABEL = "pre_commit"       }

  }
}
stage ("Build") {

  options {
    lock(*label: "${env.NODE_LABEL}"*, variable: "NODELABEL", quantity: 1)
  }
  steps {
    script {
      sh "echo \"${env.NODELABEL}\""
    }

   }

}

}
}
{code}
 

*Console Output :*
 
{code}
+refs/heads/master:refs/remotes/origin/master # timeout=10
Checking out Revision 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10
Commit message: "send slack for only master builds"
> git rev-list --no-walk 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10[Pipeline] nodeRunning on [codereview1.eng.nutanix.com|http://erdinger.eng.nutanix.com/computer/codereview1.eng.nutanix.com/] in /root/workspace/QA/test_lock[Pipeline] {[Pipeline] stage[Pipeline] { (Setup)[Pipeline] script[Pipeline]

{[Pipeline] }

[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Build)[Pipeline] lockTrying to acquire lock on [Label: null, Quantity: 1]
Found 0 available resource(s). Waiting for correct amount: 1.
*[Label: null, Quantity: 1] is locked, waiting...*
  {code}

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource as label value is coming as null.
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

tobias-jenkins@23.gs (JIRA)

unread,
Oct 4, 2019, 8:45:04 PM10/4/19
to jenkinsc...@googlegroups.com
Tobias Gruetzmacher updated an issue
Lockable Resource Plugin Version: 2.3

I am trying to use env variable in label field and the resource doesn't get locked. The job gets stuck infinitely waiting for the resource even though env variable is set.

 
{code}
pipeline {

agent

{   node

    node { label 'centos_node' }

}

stages {
  stage("Setup") {
    steps {
      script

{        
env.NODE_LABEL = "pre_commit"      
}

 
}
}
stage ("Build") {

 
options {
    lock( * label: "${env.NODE_LABEL}" * , variable: "NODELABEL", quantity: 1)
  }
  steps {
    script {
      sh "echo \"${env.NODELABEL}\""
    }

   
}

}

}
}
{code}
 

*Console Output :*
 
{code}
+refs/heads/master:refs/remotes/origin/master # timeout=10
Checking out Revision 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 (master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10
Commit message: "send slack for only master builds"
> git rev-list --no-walk 9db4337fd2811d9ebce79f1761ef40a88ec16fb2 # timeout=10[Pipeline] nodeRunning on
[ codereview1.eng.nutanix.com |http://erdinger.eng.nutanix.com/computer/codereview1.eng.nutanix.com/] in /root/workspace/QA/test_lock[Pipeline] {[Pipeline] stage[Pipeline] { (Setup)[Pipeline] script[Pipeline]

{[Pipeline] }

[Pipeline] // script[Pipeline] }[Pipeline] // stage[Pipeline] stage[Pipeline] { (Build)[Pipeline] lockTrying to acquire lock on [Label: null, Quantity: 1]
Found 0 available resource(s). Waiting for correct amount: 1.
*[Label: null, Quantity: 1] is locked, waiting...*
  {code}

 

A lock should get acquired by resource with label 'pre_commit' but it is infinitely waiting for the resource as label value is coming as null.

tobias-jenkins@23.gs (JIRA)

unread,
Oct 4, 2019, 8:51:02 PM10/4/19
to jenkinsc...@googlegroups.com

Can you change the lockable resource plugin so that the name of the resource is determined when the plugin is executed and not at the beginning of the pipeline?

No, I cannot. What you are experiencing here are the normal scoping rules of declarative pipeline: The options blocks are "run" when the declarative pipeline is build, while the steps block is run when the pipeline is executed. If you want a different order, you need to fall back to scripted pipeline. (Or report a bug against the declarative pipeline plugin, but I suspect this is considered part of the design)

tobias-jenkins@23.gs (JIRA)

unread,
Oct 4, 2019, 8:51:04 PM10/4/19
to jenkinsc...@googlegroups.com
Tobias Gruetzmacher closed an issue as Not A Defect
 
Change By: Tobias Gruetzmacher
Status: Open Closed
Resolution: Not A Defect
Reply all
Reply to author
Forward
0 new messages