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

ExportXMLWordPrintable

      When defining environment variables both in a declarative pipeline running a docker agent, and in the jenkins master process environment itself, then the environment variable is missing in the docker agent.

      Scenario:

       

      Jenkins setup:

      Using jenkins:lts docker image, with docker socket forwarded in the jenkins docker container for it to use docker agents; with extra environment variables:

      $ docker run -e FOO=bar -e FOO2=bar -e FOO3=bar -v /var/run/docker.sock:/var/run/docker.sock -v $(which docker):/usr/bin/docker --init -v jenkins_home:/var/jenkins_home -p 8080:8080 -p 50000:50000 --name jenkins jenkins/jenkins:lts
      # hack to add missing depencies on the docker cli, and fix permissions issues
      $ docker exec -u 0 jenkins bash -c "apt-get update && apt-get install libltdl7 && chown -R jenkins:jenkins /var/run/docker.sock"
      

      Setup jenkins with usual plugins (no manual selection).

      Pipeline job:

      Create a pipeline with the following declarative pipeline:

      pipeline {
          agent { docker 'ubuntu:16.04' }
      
          environment {
              FOO = 'bar'
              FOO2 = 'different'
          }
          stages {
              stage('Test') {
                  steps {
                      sh 'echo FOO: ${FOO:-error}'
                      sh 'echo FOO2: ${FOO2:-error}'
                      sh 'echo FOO3: ${FOO3:-error}'
                  }
              }
          }
      }
      

      Run the job

      [env-bug] Running shell script
      + echo FOO: error
      FOO: error
      [Pipeline] sh
      [env-bug] Running shell script
      + echo FOO2: different
      FOO2: different
      [Pipeline] sh
      [env-bug] Running shell script
      + echo FOO3: error
      FOO3: error
      

      Analysis

      Scenario explanation:

      • start jenkins with env vars FOO=bar and FOO2=bar and FOO3=bar
      • pipeline redeclares FOO=bar (same value) and FOO3=different (different value)
      • result: FOO disappears in the shell environment in docker agent, FOO2 is OK, FOO3 is not there (not forwarded from jenkins environment, it's an extra test).

            Assignee:
            Unassigned
            Reporter:
            Thomas Riccardi
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: