jenkinsci / jenkinsci/docker-workflow-plugin

[JENKINS-64597] Jenkins docker plugin global variables override image arguments

Open
#661 0 comments 0 reactions 0 assignees View on GitHub
component:docker-workflow-plugin enhancement imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
527
Forks
422
Avg merge
10m
Merged PRs (30d)
1

Description

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:



  1. Create a global environment variable MY_VAR=value1

  2. 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('').inside('-e MY_VAR=value2') {
      sh 'env | grep MY_VAR'
      }
      }
      }
      }
      }
      }





  1. 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 ******** 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

    ```


---
Originally reported by mrichar2, imported from: Jenkins docker plugin global variables override image arguments


  • status: Open
  • priority: Minor
  • component(s): docker-workflow-plugin
  • resolution: Unresolved
  • votes: 0
  • watchers: 1
  • imported: 2025-12-07

Raw content of original issue

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:



  1. Create a global environment variable MY_VAR=value1

  2. 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'
      }
      }
      }
      }
      }
      }






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


  • environment: Jenkins 2.222.4

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.