<p>I'm running <strong>perfomance tests</strong> on Jenkins. Test that may <strong>include multiple instances of the same container</strong> to generate necessary load. I can't hardcode number of instances as it varies based on params for tests.
I've tried to use the following code:</p>
<pre><code>pipeline {
agent any
stages {
  stage('Running Jmeter') {
    agent {
      kubernetes {
          label &quot;jmeter_tests_executor&quot;
          yaml '''
          apiVersion: batch/v1
          kind: Job
          metadata:
            name: jmeter
            namespace: jenkins
          spec:
            parallelism: 2 
            backoffLimit: 1 
            ttlSecondsAfterFinished: 100
          ...
</code></pre>
<p>But it doesn't work. It's hanging on pod scheduling(jobs works ok if you apply this manifest directly on kubernetes cluster without Jenkins).<br />
If someone had experience with it, please share your workarounds or ideas how to implement this idea.</p>

DavidGreen55
<p>Maybe try something like this</p>
<pre><code>stage(&quot;RUN LOAD TEST&quot;) {
    steps {
        script {
            //params.each creates an array of stages
            paramsToTest.each {param -&gt; 
                load[&quot;load test&quot;] = {
                    stage(&quot;Executing run ${param}&quot;) {
                        agent {
                            kubernetes {
                                label &quot;jmeter_tests_executor&quot;
                                yaml '''
                                apiVersion: batch/v1
                                kind: Job
                                metadata:
                                name: jmeter
                                namespace: jenkins
                                spec:
                                parallelism: 2 
                                backoffLimit: 1 
                                ttlSecondsAfterFinished: 100
                                ...
                                '''
                            }    
                        }
                        steps {
                            &lt;EXECUTE LOAD TEST COMMAND&gt;
                        }
                    }
                }
                parallel(load) //actually executes the parallel stages
            }
        }
    }
}
</code></pre>
<p>What this does is use an array of something and then generates stages based on that array. The agent params in the stage should tell Jenkins to create a new pod with each execution in parallel.</p>
