If you have multiple nodes with a label of A, you will need to declare a variable to hold the name of the specific node you ended up on in the first "node" declaration, and then use that node in the third one:
def allocatedNode node('A') { allocatedNode = $NODE_NAME } //NODE_NAME is an environment variable provided by Jenkins node('B') {} node($NODE_NAME) {} HOWEVER, be aware that this isn't always a safe thing to do, depending on what your goal is. There is no guarantee that the workspace that was used in the first node block will still be there when the third block gets there. Even if it is, there is no guarantee that the third block will use the original workspace. It probably will most of the time, but not guaranteed. Depending on what you are doing, you may need to allocate a custom workspace (still not a guaranteed solution), move to a separate directory, stash/unstash the things you need between nodes, or some other solution. On Sunday, October 29, 2017 at 8:51:02 PM UTC-6, Daniel Becroft wrote: > > Hi, > I'm experimenting with the scripted pipeline, and have a question about > the use of node('') with a label. If I have the following scenario: > > node('A') { } > node('B') { } > node('A') { // Which node will be used here? } > > Is there any guarantee that the second node() step for "A" will hit the > same slave as the first one, or will it use whichever slave is now > available? I'd like for the first node() to allocate one from the pool of > slaves with the label of "A", but then the second one to somehow reuse the > first one (there might be some cleanup tasks, etc that need to happen on > the original node). > > Cheers, > Daniel B. > > -- 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 jenkinsci-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f43a48c1-15bd-4feb-9a91-3e818a3cf268%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.