I just made a suggestion on a similar thread 
<https://groups.google.com/d/msg/jenkinsci-users/41bKAIfrPAw/zpuyg__7AAAJ>. 
Does lock work inside a steps block? Or a script block? It seems like it 
should, because it is a step that does something imperatively.

On Thursday, March 7, 2019 at 3:58:59 PM UTC-8, Dusan Nikolov wrote:
>
> Hi, 
> I'm trying to figure out how/if it's possible to create a lock that will 
> guard multiple stages of a pipeline execution, based on the NODE_NAME on 
> which they are supposed to execute.
>
> I tried putting the lock in the options block of the surrounding stage, 
> but this throws an error because options block in a stage is 
> executed/evaluated before agent block.
> Please see the example pipeline below for reference:
>
> pipeline {
> agent none
> stages {
> stage ('main') {
> parallel {
> stage ('server') {
> agent { label 'server' }
> // options { lock(NODE_NAME) }
> stages {
> stage ('all') {
> options { lock("${NODE_NAME}") } // this also seems to fail
> steps {
> script {
> echo "${NODE_NAME}"
> sleep(10)
> }
> }
> }
> }
> }
> stage ('client') {
> agent { label 'client' }
> stages {
> stage ('all') {
> options { lock("${NODE_NAME}") }
> steps {
> script {
> echo "${NODE_NAME}"
> sleep(10)
> }
> }
> }
> }
> }
> }
> }
> }
> }
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/0e87d972-12b5-4b51-ae2d-7f269f417b5a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to