I need to allocate the same nodes in different stages in a jenkins pipeline. the scenario is that I need to run distributed JMeter test and I create a pipeline as follows:
- stage1: set up some agents in parallel, e.g fetch source code and tests, compile sources and install dependencies, run the jmeter-server as a daemon process, get IP address of current node.
- stage2: allocate the same nodes in stage1 and use one node as the JMeter master node in which it passes the list of IP Address of all nodes in stage1 to JMeter.sh process for running distributed test.
node("master"){
def LIST_IP_ADDRESS_NODES=[]
stage("Setup-JMeter-Agent"){
parallel "node1":{
node("specifice-label"){
//fetch souces code and test.
//compile sources
//install dependencies
// start JMeter-server
//get IP Address
LIST_IP_ADDRESS_NODES.add(current_ip)
}
},
"node2":{
node("specifice-label"){
//fetch souces code and test.
//compile sources
//install dependencies
// start JMeter-server
//get IP Address
LIST_IP_ADDRESS_NODES.add(current_ip)
}
}
}
stage("Run-Jmeter-Test"){
parallel "node1":{
node("specific-label"){
//run jmeter.sh with the list of IP address of nodes in stage1.
}
},
"node2":{
node("specific-label"){
waitUntil {
// check if JMeter-master is finished.
}
}
}
}
}
the problem is that how to make sure the nodes allocated in stage2 are the same nodes in stage1? the pipeline will fail if a another concurrent job allocates some nodes with the label specific-label
set up in stage1, consequently stage2 will allocate some clean nodes and fail to run tests.
I guess the probability of allocating different nodes in stage1 and stage2 may increase when there are more number of nodes with the label specific-label
than 2 nodes required by the pipeline and causes failure of the pipeline more frequently. So I wonder if there is mechanism like lock
in programming language which can lock the nodes in stage1 and reserve the nodes for use in stage2.
Thanks.