-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Minor
-
Component/s: kubernetes-plugin
-
Environment:Jenkins 2.346.3 and 2.303.3
Kubernetes plugin 3704.va_08f0206b_95e and 1.31.3
Steps to reproduce:
- Create a pod template with a pod level environment variable
- Create a pipeline job with
- Inherit from the template in 1
- Add another container and set it is as the default container
- Add a global environment section container the SAME key value pair as the pod template env var
- Add a stage using the default container (no container section, just steps) and dump the env
- Add another stage explicitly within a container() section with the container from step 2 and dump the env
- When running the pipeline, you will notice that the env var will print from the stage in step 5 above but NOT from step 4
Example pipeline:
pipeline {
  agent {
    kubernetes {
      inheritFrom "mypodtemplate"
      defaultContainer 'mycontainer'
      yaml '''
spec:
 containers:
 - name: mycontainer
  image: ubuntu:latest
  command: [cat]
  tty: true
        '''
    }
  }
  environment {
    // use the SAME key value pair in the pod template env vars section
    ENV_VAR = 'foo'
  }
  stages {
    stage("ENV_VAR PRESENT here") {
      steps {
        container('mycontainer') {
          sh """
            env
          """
        }
      }
    }
    stage("ENV_VAR NOT PRESENT here") {Â
      steps {
        sh """
          env
        """
      }
    }
  }
}
Template:
clouds: Â - kubernetes: Â ... Â Â Â templates: Â Â Â ... Â Â Â - envVars: Â Â Â Â - envVar: Â Â Â Â Â Â key: "ENV_VAR" Â Â Â Â Â Â value: "foo" Â Â Â Â inheritFrom: "jnlp" Â Â Â Â label: "mypodtemplate" Â Â Â Â name: "mypodtemplate" Â Â Â Â yamlMergeStrategy: "override"
Â