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

Environment variables missing when both defined in pipeline and jenkins master process environment with docker agent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • docker-workflow-plugin
    • None
    • jenkins 2.73.3, from LTS docker image
      host: ubuntu 16.04 with docker-ce 17.09

      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).

            Unassigned Unassigned
            thomas_deepomatic Thomas Riccardi
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: