wrong workspace picked up by node(..) when running parallel jobs

19 views
Skip to first unread message

Torsten Reinhard

unread,
Oct 25, 2017, 7:15:39 PM10/25/17
to Jenkins Users
Hi,

this pipeline sample fails, when started multiple times and running in parallel at the same time.
Assigning a captured node again seems to be not enough - the workspace isn´t matching than what will lead to very strange behaviour.

import com.cloudbees.groovy.cps.NonCPS

String buildNode
String buildNodeWS

@NonCPS
assertWorkspaces
(current, expected ) {
   
assert current == expected
}

node
() {
    buildNode
= env.NODE_NAME
    buildNodeWS
= env.WORKSPACE
    echo
"performing build on node ${buildNode} in ${buildNodeWS}"
}

checkpoint
("built")
node
('sdp') {
    echo
"running on any node, currently it´s ${env.NODE_NAME}"
}
checkpoint
("deployed")

node
( buildNode ) {
   
String currentWS = env.WORKSPACE
    echo
"running on ${buildNode} again - it´s ${env.NODE_NAME} in ${currentWS}"
   
    assertWorkspaces
(currentWS, buildNodeWS)
}

Do I have to manage the workspace by myself - or is that a bug to be reported?

What do you think ?

Torsten

Robert Hales

unread,
Oct 25, 2017, 10:25:51 PM10/25/17
to Jenkins Users
There is no guarantee that you will get the same workspace on a node. It will try, but a workspace can only be in use by 1 job at a time. So if you require a specific workspace, you have a few options: 

Define a custom workspace with the ws step. But I think 2 jobs still can't use it at the same time.
Stash/unstash the files you need to persist across nodes or stages
set into a directory outside of the workspace to do what needs to be shared
Use resource locking so that other jobs wait to access the workspace. Still not guaranteed to get the same workspace. 
Use resource locking combined with ws to specify a specific workspace and other jobs will wait for access to it. 
Specify a custom workspace and don't allow the job to run more than 1 build at a time. 
Reply all
Reply to author
Forward
0 new messages