title: Passing variable to jenkins yaml podTemplate
body: <p>I am using Jenkins with the kubernetes plugin to run my jobs and I need to run a pipeline that:</p>
  <ol>
  <li>builds a docker image</li>
  <li>submit it to the registry</li>
  <li>Uses that same image in the following steps to perform the tests.</li>
  </ol>
  <pre><code>Container(image:A): build image B 
  Container(image:B) : test image B
  </code></pre>
  <p>So I would like to use variables and substitute them inside the kubernetes podtemplate as here:</p>
  <pre><code>pipeline {
    agent none
    stages {
      stage(&quot;Build image&quot;){
          // some script that builds the image
          steps{
              script{
                  def image_name = &quot;busybox&quot;
              }
          }
      }
      stage('Run tests') {
        environment {
          image = &quot;$image_name&quot;
        }
        agent {
          kubernetes {
            yaml &quot;&quot;&quot;\
          apiVersion: v1
          kind: Pod
          metadata:
            labels:
              some-label: some-label-value
          spec:
            containers:
            - name: busybox
              image: &quot;${env.image}&quot;
              command:
              - cat
              tty: true
          &quot;&quot;&quot;.stripIndent()
          }
        }
        steps {
          container('busybox') {
            sh 'echo &quot;I am alive!!&quot;'
          }
        }
      }
    }
  }
  </code></pre>
  <p>but the variable is empty as I get:</p>
  <pre><code>[Normal][ci/test-10-g91lr-xtc20-s1ng1][Pulling] Pulling image &quot;null&quot;
  [Warning][ci/test-10-g91lr-xtc20-s1ng1][Failed] Error: ErrImagePull
  [Warning][ci/test-10-g91lr-xtc20-s1ng1][Failed] Failed to pull image &quot;null&quot;: rpc error: code = Unknown desc = Error response from daemon: pull access denied for null, repository does not exist or may require 'docker login': denied: requested access to the resource is denied
  </code></pre>
  <p>Do you know how I can achieve a similar behaviour ?</p>