<h2>In General</h2>

<p>I'm trying to use label when using <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="nofollow noreferrer">kubernetes-plugin</a> for Jenkins, but I get a little bit confused.
In my <code>pipeline</code> bellow I'm trying to build test job in <code>parallel</code> steps with different labels (agents).</p>

<p>I already have configured the plugin with pod template and container in my Jenkins config, where I use same settings as it's in the pipeline <code>podTemplate</code> defined.</p>

<h2>Issue</h2>

<p>The problem is that when I use <code>agent label</code> in stage 2 there is jnpl image running instead the image that I point in the config <code>someimage:latest</code>.</p>

<p>In <code>stage 1</code> where I define the pod in pipeline there is no problem and the required images are running fine.</p>

<h2>Question</h2>

<p><em>What I'm doing wrong?</em>
Here is my <code>jenkinsfile</code> and config of the <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="nofollow noreferrer">kubernetes-plugin</a> in Jenkins:</p>

<pre><code>def podTemplate = """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: k8s
    image: someimage:latest
    command:
    - sleep
    args:
    - infinity
    volumeMounts:
      - name: workspace-volume
        mountPath: /home/jenkins/agent
    workingDir: "/home/jenkins/agent"
  volumes:
      - name: "workspace-volume"
        persistentVolumeClaim:
          claimName: "jenkins-worker-pvc"
          readOnly: false
"""
pipeline {
    agent none
    stages {
        stage("Parallel") {
            parallel {
                stage("1.k8s") {
                    agent {
                        kubernetes {
                            yaml podTemplate
                            defaultContainer 'k8s'
                        }
                    }
                    steps {
                        sh """
                            mvn -version
                        """
                    }
                }
                stage("2. k8s") {
                    agent { label 'k8s' }
                    steps {
                        sh """
                            mvn -version
                        """
                    }
                }
                stage("win") {
                    agent { label 'windows' }
                    steps {
                        bat "dir"
                    }
                }
            }
        }
    }
}
</code></pre>

<p><a href="https://i.stack.imgur.com/JyRL5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JyRL5.png" alt="enter image description here"></a></p>

<p>You did not specified an image for <code>stage</code> with <code>label</code> <code>k8s</code> and <code>windows</code>.</p>

<p>You can read in the <a href="https://github.com/jenkinsci/kubernetes-plugin" rel="noreferrer">docs</a> that:</p>

<blockquote>
  <p>The plugin creates a Kubernetes Pod for each agent started, defined by the Docker image to run, and stops it after each build.</p>
  
  <p>Agents are launched using JNLP, so it is expected that the image connects automatically to the Jenkins master.</p>
</blockquote>

<p>You are using <code>podTemplate</code> and I would advice setting up <a href="https://jenkins.io/doc/pipeline/steps/kubernetes/#podtemplate-define-a-podtemplate-to-use-in-the-kubernetes-plugin" rel="noreferrer"><code>container</code></a> , this might look like the following:</p>

<pre class="lang-yaml prettyprint-override"><code>podTemplate(containers: [
    containerTemplate(name: 'maven', image: 'maven:3.3.9-jdk-8-alpine', ttyEnabled: true, command: 'cat'),
    containerTemplate(name: 'golang', image: 'golang:1.8.0', ttyEnabled: true, command: 'cat')
  ]) {

    node(POD_LABEL) {
        stage('Get a Maven project') {
            git 'https://github.com/jenkinsci/kubernetes-plugin.git'
            container('maven') {
                stage('Build a Maven project') {
                    sh 'mvn -B clean install'
                }
            }
        }

        stage('Get a Golang project') {
            git url: 'https://github.com/hashicorp/terraform.git'
            container('golang') {
                stage('Build a Go project') {
                    sh """
                    mkdir -p /go/src/github.com/hashicorp
                    ln -s `pwd` /go/src/github.com/hashicorp/terraform
                    cd /go/src/github.com/hashicorp/terraform &amp;&amp; make core-dev
                    """
                }
            }
        }

    }
}
</code></pre>

<p>You can read more about <a href="https://github.com/jenkinsci/kubernetes-plugin#container-configuration" rel="noreferrer">Container Configuration</a> and <a href="https://github.com/jenkinsci/kubernetes-plugin#container-group-support" rel="noreferrer">Container Group Support</a></p>
