<p>I am using jenkins and kubernetes,
each time I trigger a job a new inbound-agent pod is created to execute the job, so far so good.</p>
<p>However, pipelines having underneath pipelines is an issue:</p>
<pre><code>pipeline {
    agent { label 'kubernetePod' }

  stages {
    
    stage('Building') {
        steps{
            build job: 'Build', parameters: []
        }
    }
    stage('Testing') {
        steps{
            build job: 'Test', parameters: []
         }
    }    
}
</code></pre>
<p>In this case, we have three pipelines</p>
<ul>
<li>'main' pipeline having 'building' stage and 'testing 'stage</li>
<li>'build' pipeline</li>
<li>'test' pipeline</li>
</ul>
<p>So a <strong>pod 'A'</strong> is created to execute the main pipeline,</p>
<p>then a <strong>pod 'B'</strong> is created to checkout and build the solution</p>
<p>finally a <strong>pod 'C'</strong> is created to execute solution tests <strong>but it crashed</strong> because the solution is contained in the <strong>pod 'B'</strong>.</p>
<p><strong>My question is how do I keep the pod 'A' for executing the underneath pipelines!</strong></p>
<p>thank you for your help.</p>
<p>best regards</p>

itbob
<p>I think that Kubernetes slaves are designed to be stateless and are meant for single use.</p>
<p>The only workaround I think may help in some cases is to use <code>idleMinutes</code> to set how long the <code>Pod</code> should be in the <code>Running</code> state.<br />
In your case if you use <code>idleMinutes</code> with appropriate values, you will be able to run <code>Build</code> and <code>Test</code> jobs using the same <code>Pod</code> (<code>podB</code> from your example).</p>
<hr />
<p>I've created an example to illustrate you how it works.</p>
<p>This is the pipeline snippet:</p>
<pre><code>pipeline {

  agent { kubernetes { 
            label 'test'
            idleMinutes &quot;60&quot;
        }}

  stages {
    
    stage('Building') {
        steps{
            build job: 'Build'
        }
    }
    stage('Testing') {
        steps{
            build job: 'Test'
    }    
}
}
}
</code></pre>
<p>This is the <code>Build</code> job:</p>
<pre><code>node('test') {
    stage('Run shell') {
        sh 'touch /home/jenkins/test_file'
        sh 'echo 123abc &gt; /home/jenkins/test_file'
    }
}
</code></pre>
<p>This is the <code>Test</code> job:<br />
<strong>NOTE:</strong> This job reads the file created by the <code>Build</code> job.</p>
<pre><code>node('test') {
    stage('Run shell') {
        sh 'cat /home/jenkins/test_file'
    }
}
</code></pre>
<p>As a result we can see that two Pods were created (<code>podA</code> and <code>podB</code> from your example) and they are still in the <code>Running</code> state:</p>
<pre><code># kubectl get pods
NAME               READY   STATUS    RESTARTS   AGE
test-99sfv-7fhw2   1/1     Running   0          4m45s
test-99sfv-vth3j   1/1     Running   0          4m25s
</code></pre>
<p>Additionally in the <code>test-99sfv-vth3j</code> <code>Pod</code> there is <code>test_file</code> created by the <code>Build</code> job:</p>
<pre><code># kubectl exec test-99sfv-vth3j -- cat /home/jenkins/test_file
123abc
</code></pre>
