Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-70190

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

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • kubernetes-plugin
    • None
    • 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" 

       

          [JENKINS-70190] Pod template env var and pipeline global env var of same name and value causes env var to disappear

          There are no comments yet on this issue.

            Unassigned Unassigned
            dg424 Donald Gobin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: