Pod template env var and pipeline global env var of same name and value causes env var to disappear

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • 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:

      1. Create a pod template with a pod level environment variable
      2. Create a pipeline job with
        1. Inherit from the template in 1
        2. Add another container and set it is as the default container
        3. Add a global environment section container the SAME key value pair as the pod  template env var
        4. Add a stage using the default container (no container section, just steps) and dump the env
        5. Add another stage explicitly within a container() section with the container from step 2 and dump the env
      3. 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" 

       

            Assignee:
            Unassigned
            Reporter:
            Donald Gobin
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: