-
New Feature
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins 2.222.4
If a global environment variable is defined it is not possible to override it with arguments passed in to the docker.image(...).inside(...) step. It appears to be because environment variables from the process added to the docker launch arguments after any user specified arguments here.
The solution could simply be to put user args last assuming it's okay / secure for users to have the ability to override any of the automatically injected arguments.
To reproduce:
- Create a global environment variable MY_VAR=value1
- Create a pipeline job with the following script that sets MY_VAR=value2 as an image arguments
pipeline { agent { label "docker" } stages { stage('Build') { steps { script { docker.image('<image>').inside('-e MY_VAR=value2') { sh 'env | grep MY_VAR' } } } } } }
- Observe the result. It prints MY_VAR=value1 instead of MY_VAR=value2
14:55:39 [Pipeline] withDockerContainer 14:55:39 jknn2t-mdjrvo does not seem to be running inside a container 14:55:39 $ docker run -t -d -u 78572:20 -e MY_VAR=value2 -w /var/appl/jenkins/workspace/sle/mrichar2_var_ordering -v /var/appl/jenkins/workspace/sle/mrichar2_var_ordering:/var/appl/jenkins/workspace/sle/mrichar2_var_ordering:rw,z -v /var/appl/jenkins/workspace/sle/mrichar2_var_ordering@tmp:/var/appl/jenkins/workspace/sle/mrichar2_var_ordering@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** <image> cat 14:55:39 $ docker top 8a93013c14625256f17f5fc2d71132333ac6aa35962da9540b1a8171a934c659 -eo pid,comm 14:55:39 [Pipeline] { 14:55:39 [Pipeline] sh 14:55:40 + env 14:55:40 + grep MY_VAR 14:55:40 MY_VAR=value1 14:55:40 [Pipeline] } 14:55:40 $ docker stop --time=1 8a93013c14625256f17f5fc2d71132333ac6aa35962da9540b1a8171a934c659 14:55:41 $ docker rm -f 8a93013c14625256f17f5fc2d71132333ac6aa35962da9540b1a8171a934c659 14:55:41 [Pipeline] // withDockerContainer 14:55:41 [Pipeline] } 14:55:41 [Pipeline] // script 14:55:41 [Pipeline] } 14:55:41 [Pipeline] // stage 14:55:41 [Pipeline] } 14:55:41 [Pipeline] // node 14:55:41 [Pipeline] End of Pipeline
- relates to
-
JENKINS-54767 Global variables are overriding local variables
- In Review