-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
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"