-
Bug
-
Resolution: Unresolved
-
Minor
-
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).
Well, that's a weird combination right there. I'm guessing that master-level env vars aren't getting passed into the docker agent, and it's seeing FOO=bar as still the master-level env var. Needs some experimentation.