Locking multiple stages with NODE_NAME based lock

52 views
Skip to first unread message

Dusan Nikolov

unread,
Mar 7, 2019, 6:58:59 PM3/7/19
to Jenkins Users
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)
}
}
}
}
}
}
}
}
}

Brian Ray

unread,
Mar 24, 2019, 1:10:59 PM3/24/19
to Jenkins Users
I just made a suggestion on a similar thread. 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.

Dusan Nikolov

unread,
Apr 3, 2019, 10:05:34 PM4/3/19
to jenkins...@googlegroups.com
Hi Brian,

I think lock works within steps and script block, however this doesn't help me. I need bigger to lock a node across several sequential stages to prevent it from being freed.

This is the use case:
Node1 and Node2 start working their parts of a stage in parallel. Parallel stages is used to, well parallelize workflow. End of first parallel block is a synchronization point (end of setup phase).
After this, nodes go into the second parallel block, where they do the testing (testing involves both nodes as a unit).

Nodes can finish phase1 at different speeds, and due to this Jenkins makes the node that is waiting on the other one available for other jobs (including a queued run of this same job). I want to prevent it from being available.

I hope I explained my use case more closely now.

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/Jlhy1hxe92M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
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.

Brian Ray

unread,
Apr 14, 2019, 7:14:41 PM4/14/19
to Jenkins Users
Now I understand. I had not considered locking a particular node for re-use in the same job. There must be some way to pin the node even if it is freed up. I will try to think of a solution.
To unsubscribe from this group and all its topics, send an email to jenkins...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages