1

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.

Jinlxz Liu
  • 421
  • 3
  • 12

2 Answers2

0

Just limit the number of concurrent jobs for nodes to 1 and once done the "another concurrent jobs" will be queuing up until your current test is finished or vice versa

Manage Jenkins > Nodes > specifice-label > Configure > # of executors

If you need more flexibility you can check whether the port 1099 (or whatever is the port you specify via server_port property) is free or not and if not - there is already a JMeter Slave process running on the node.

More information: How to Perform Distributed Testing in JMeter

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Your approach should work, but I feel it's not perfect, in case that another job with different name which also allocate nodes with the same label during the gap between stage1 and stage2 may cause my pipeline fail, 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. – Jinlxz Liu Apr 13 '20 at 10:38
0

You may want to examine declarative pipeline, where any stages that are not specifically asking for a node can all run on the same node allocated to these stages' parent nodes. See e.g. here.

In your case this might look something like this:

pipeline {
    agent none
    stages {
        stage('Run Tests') {
            parallel {
                stage('Node1') {
                    agent {
                        label "specifice-label" // here node is selected
                    }
                    stages {
                         stage('Start') {  // this will run on the node selected above 
                              steps { 
                                 // fetch/compile/install/start JMeter
                              }
                         }
                         stage('Test') {  // this will run on the same node 
                              steps { 
                                 // run jmeter
                              }
                         }

                    }
                }
                stage('Node2') {
                    agent {
                        label "specifice-label" // this will select another node
                    }
                    // same as above 
                }
            }
        }
    }
}
MaratC
  • 6,418
  • 2
  • 20
  • 27
  • this is not what I need, It does not use the capability of JMeter's distributed testing. – Jinlxz Liu Apr 13 '20 at 14:31
  • This answers the question "how to make sure the nodes allocated in stage2 are the same nodes in stage1?". You're welcome :) – MaratC Apr 13 '20 at 15:54
  • Is it possible to have this with a dynamic amount of Nodes? I.e. if I want my jmeter job to run from a variable amount of nodes. – David Schumann Jun 10 '21 at 09:07
  • I would suggest asking a separate question, as the context is unclear to me. – MaratC Jun 10 '21 at 13:06