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

env vars are not consistent

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • docker-workflow-plugin
    • None
    • jenkins 2.287
      docker-plugin: 1.2.2
      docker-workflow: 1.2.6

      I'm trying to do something like this:

      node {
          stage('reproduce') {
              sh """
                  echo '1'
                  printenv PATH
                  echo "$PATH"
              """
              docker.image('python:3.6.4-slim').inside {
                  sh """
                      echo '2'
                      printenv PATH
                      echo "$PATH"
                  """
                  withEnv(["PATH=$PATH:/my/custom/path"]) {
                      sh """
                          echo '3'
                          printenv PATH
                          echo "$PATH"
                      """
                  }
              }
          }
      }
      

      sh (1) gives me:

      + printenv PATH
      /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      + echo /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
      /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

      all is good so far

      sh (2) gives me:

      + printenv PATH
      /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      + echo /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 
      /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

      which is already confusing

      sh (3) gives:

      + printenv PATH
      /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
      + echo /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/my/custom/path 
      /opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/my/custom/path

       

      I have couple of questions about this:

      • why printenv and echo in sh(2) show different results? sounds like printenv prints original env which comes from docker image while echo prints value from host jenkins.
      • why withEnv which is executed inside docker container does not modify docker's PATH but modifies Jenkins's PATH.

            Unassigned Unassigned
            spugachev Stanislav Pugachov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: