Answers: <p><a href="https://support.cloudbees.com/hc/en-us/articles/226520788-Control-environment-variables-inside-a-Docker-container" rel="nofollow noreferrer">This post explains that/why environment variables don't propagate to Docker agent</a>.</p>
  <p>If you need a custom container, you could define path and whatever else as layers on top of base image in a Dockerfile. Then using that image in pipeline would be what I think is usual way of doing it. You can build that image outside of Jenkins, but it's also possible to <a href="https://www.jenkins.io/doc/book/pipeline/docker/#building-containers" rel="nofollow noreferrer">build container from within pipeline too</a> if you want (get Dockerfile from SCM or some other use case).</p>
  <p>In the context of your question, I think you can still use base image, and if you know full path you'd like to set, do that at container (agent) startup with args. But <code>$PATH</code> variable won't be available at host to be resolved within container at startup. If you must dynamically set path in container, could adjust it in shells.</p>
  <pre><code>pipeline {
      agent {
          docker { 
              image 'python:3.9'
              // cannot resolve $PATH var in container (becasue HOST does not know what it is).
              args '-e PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/i/know/my/full/path/ahead/of/time'
          }
      }
      stages {
          stage('Test') {
              steps {
                  
                  // as set by args above. Applies to all shells
                  sh 'echo $PATH'
                  
                  // You can also adjust it within container in each shell
                  sh '''
                      export PATH=/even/more/path:$PATH
                      echo $PATH
                     '''
  
                  // But this is back to what's in args in a new shell instance
                  sh 'echo $PATH'
              }
          }
      }
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-01-15T11:51:16.517Z
Answers: Thank you @napovi for the answer, I ran your example with using `args` but still the same error.
Answers: dubaksk
Answers: CC BY-SA 4.0
Answers: 2021-01-15T16:35:35.110Z
Answers: Still getting 'bogus path' error? That would be odd, because you are not altering any paths in Jenkins/Pipeline in my example. Only passing absolute path to be set in the container or prepend it to your command in a `sh` block without string interpolation (single quotes). Could you post what you got now in your pipeline?
Answers: apo
Answers: CC BY-SA 4.0
Answers: 2021-01-15T21:18:27.393Z
Answers: I took your example and ran it inside provided Jenkins server and I got the same `bogus PATH` error. It is very weird indeed.
Answers: dubaksk
Answers: CC BY-SA 4.0
Answers: 2021-01-15T08:41:55.247Z
Answers: 2021-01-15T11:28:07.320Z
Answers: 2021-01-15T11:28:07.320Z
Answers: apo
Answers: <p>If you are not using Docker using in built support in pipeline and instead, if you are setting up docker agent manually from &quot;Manage Jenkins -&gt; Clouds -&gt; Docker template&quot;, then below solution will work as provided in this <a href="https://stackoverflow.com/questions/43237051/how-to-set-path-in-jenkins-declarative-pipeline">Stackoverflow post</a>.</p>
  <pre><code>pipeline {
    agent { label 'docker-custom-image' }
    environment {
          JAVA_HOME='/opt/java-se-8u44-ri'
          PATH = &quot;$JAVA_HOME/bin/:${env.PATH}&quot;
    }
    stages {
      stage ('build') {
        steps {
          echo &quot;PATH is: ${env.PATH}&quot;
        }
      }
    }
  }
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-07-27T19:56:08.333Z
Answers: 2024-07-27T19:56:08.333Z
Answers: learner
Body: <p>I am struggling with this issue inside my declarative pipeline. I am trying to use python's docker image as my agent and run some scripts and I am receiving warning:</p>
  <pre><code>Warning: JENKINS-41339 probably bogus PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools; perhaps you meant to use ‘PATH+EXTRA=/something/bin’
  </code></pre>
  <p>I do not have access to Jenkins server global variables configuration. I am using one of the Debian slaves.</p>
  <p>I have read other issues about this problem <a href="https://stackoverflow.com/questions/43987005/jenkins-does-not-recognize-command-sh">stackoverflow/43987005</a> and <a href="https://stackoverflow.com/questions/44378221/export-command-in-jenkins-pipeline/">stackoverflow/44378221</a>. Also discussion on <a href="https://issues.jenkins.io/browse/JENKINS-41339" rel="nofollow noreferrer">Jenkins forum</a> and Jenkins official <a href="https://www.jenkins.io/doc/book/pipeline/docker/" rel="nofollow noreferrer">documentation</a>.</p>
  <p>This is code I am executing:</p>
  <pre><code>//  https://www.jenkins.io/doc/book/pipeline/syntax/
  pipeline {
    environment {
      PATH = &quot;/bin/sh:$PATH&quot;
    }
    agent {
      docker {
        image &quot;python:3.9&quot;
      }
    }
    stages {
      stage('Test') {
        steps {
          withEnv([&quot;PATH+EXTRA=$PATH&quot;]) {
            sh &quot;PATH is: $PATH&quot;
          }
        }
        post {
          cleanup {
            cleanWs()
          }
        }
      }
      stage('Build') {
        steps {
          echo &quot;'Let's build&quot;
        }
      }
      stage('Deploy') {
        steps {
          echo &quot;'Let's deploy&quot;
        }
      }
    }
  }
  </code></pre>
  <p>Problem appeared after I wanted to implement docker image as agent and by changing <em><strong>environment</strong></em> section inside my pipeline still haven't fixed my problem. I was trying also these alternatives:</p>
  <pre><code>PATH = &quot;/usr/local/bin:$PATH&quot;
  PATH = &quot;/usr/local/bin:${env.PATH}&quot;
  </code></pre>
  <p>I also went to <code>Configure</code>, section <code>Prepare an environment for the run</code> and filled up <code>Properties Content</code> input but I still didn't receive $PATH content into my job. I am still receiving global value of $PATH. I also unchecked the <code>Keep Jenkins Environment Variables</code> checkbox.</p>
  <p>The server I am using has <a href="https://plugins.jenkins.io/envinject/" rel="nofollow noreferrer">Environment Injector Plugin</a> plugin installed.</p>
  
Comments: CC BY-SA 4.0
Comments: 2021-01-11T23:58:11.237Z
Comments: Looks like this question is already asked and answered over on stack overflow: https://stackoverflow.com/questions/43987005/jenkins-does-not-recognize-command-sh
Comments: jayhendren
Comments: CC BY-SA 4.0
Comments: 2021-01-12T07:28:38.913Z
Comments: @jayhendren I was reading that, even mentioned it at the beginning of my answer, but unfortunately nothing helped me so far.
Comments: dubaksk
Tags: <jenkins><jenkins-pipeline><jenkinsfile>
Title: Jenkins declarative pipeline Warning: JENKINS-41339 probably bogus PATH
UserDisplayName: dubaksk
ThreadText: # Jenkins declarative pipeline Warning: JENKINS-41339 probably bogus PATH
  
  (Asked by: username_0 on 2021-01-11)
  
  I am struggling with this issue inside my declarative pipeline. I am trying to use python's docker image as my agent and run some scripts and I am receiving warning:
  
  ```
  Warning: JENKINS-41339 probably bogus PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:/opt/android-sdk-linux/tools:/opt/android-sdk-linux/platform-tools; perhaps you meant to use ‘PATH+EXTRA=/something/bin’
  
  ```
  
  I do not have access to Jenkins server global variables configuration. I am using one of the Debian slaves.
  
  I have read other issues about this problem [stackoverflow/43987005](https://stackoverflow.com/questions/43987005/jenkins-does-not-recognize-command-sh) and [stackoverflow/44378221](https://stackoverflow.com/questions/44378221/export-command-in-jenkins-pipeline/). Also discussion on [Jenkins forum](https://issues.jenkins.io/browse/JENKINS-41339) and Jenkins official [documentation](https://www.jenkins.io/doc/book/pipeline/docker/).
  
  This is code I am executing:
  
  ```
  //  https://www.jenkins.io/doc/book/pipeline/syntax/
  pipeline {
    environment {
      PATH = "/bin/sh:$PATH"
    }
    agent {
      docker {
        image "python:3.9"
      }
    }
    stages {
      stage('Test') {
        steps {
          withEnv(["PATH+EXTRA=$PATH"]) {
            sh "PATH is: $PATH"
          }
        }
        post {
          cleanup {
            cleanWs()
          }
        }
      }
      stage('Build') {
        steps {
          echo "'Let's build"
        }
      }
      stage('Deploy') {
        steps {
          echo "'Let's deploy"
        }
      }
    }
  }
  
  ```
  
  Problem appeared after I wanted to implement docker image as agent and by changing ***environment*** section inside my pipeline still haven't fixed my problem. I was trying also these alternatives:
  
  ```
  PATH = "/usr/local/bin:$PATH"
  PATH = "/usr/local/bin:${env.PATH}"
  
  ```
  
  I also went to `Configure`, section `Prepare an environment for the run` and filled up `Properties Content` input but I still didn't receive $PATH content into my job. I am still receiving global value of $PATH. I also unchecked the `Keep Jenkins Environment Variables` checkbox.
  
  The server I am using has [Environment Injector Plugin](https://plugins.jenkins.io/envinject/) plugin installed.
  
  **Tags:** jenkins, jenkins-pipeline, jenkinsfile
  
  > **Comments:**
  > **username_1**: Looks like this question is already asked and answered over on stack overflow: https://stackoverflow.com/questions/43987005/jenkins-does-not-recognize-command-sh  
  > **username_0**: @username_1 I was reading that, even mentioned it at the beginning of my answer, but unfortunately nothing helped me so far.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2021-01-15. Score: 2
  
  [This post explains that/why environment variables don't propagate to Docker agent](https://support.cloudbees.com/hc/en-us/articles/226520788-Control-environment-variables-inside-a-Docker-container).
  
  If you need a custom container, you could define path and whatever else as layers on top of base image in a Dockerfile. Then using that image in pipeline would be what I think is usual way of doing it. You can build that image outside of Jenkins, but it's also possible to [build container from within pipeline too](https://www.jenkins.io/doc/book/pipeline/docker/#building-containers) if you want (get Dockerfile from SCM or some other use case).
  
  In the context of your question, I think you can still use base image, and if you know full path you'd like to set, do that at container (agent) startup with args. But `$PATH` variable won't be available at host to be resolved within container at startup. If you must dynamically set path in container, could adjust it in shells.
  
  ```
  pipeline {
      agent {
          docker { 
              image 'python:3.9'
              // cannot resolve $PATH var in container (becasue HOST does not know what it is).
              args '-e PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/i/know/my/full/path/ahead/of/time'
          }
      }
      stages {
          stage('Test') {
              steps {
                  
                  // as set by args above. Applies to all shells
                  sh 'echo $PATH'
                  
                  // You can also adjust it within container in each shell
                  sh '''
                      export PATH=/even/more/path:$PATH
                      echo $PATH
                     '''
  
                  // But this is back to what's in args in a new shell instance
                  sh 'echo $PATH'
              }
          }
      }
  }
  
  ```
  
  > **Comments:**
  > **username_0**: Thank you @napovi for the answer, I ran your example with using `args` but still the same error.  
  > **username_2**: Still getting 'bogus path' error? That would be odd, because you are not altering any paths in Jenkins/Pipeline in my example. Only passing absolute path to be set in the container or prepend it to your command in a `sh` block without string interpolation (single quotes). Could you post what you got now in your pipeline?  
  > **username_0**: I took your example and ran it inside provided Jenkins server and I got the same `bogus PATH` error. It is very weird indeed.  
  
  ---
  
  ### Answer by username_3 on 2024-07-27. Score: 0
  
  If you are not using Docker using in built support in pipeline and instead, if you are setting up docker agent manually from "Manage Jenkins -> Clouds -> Docker template", then below solution will work as provided in this [Stackoverflow post](https://stackoverflow.com/questions/43237051/how-to-set-path-in-jenkins-declarative-pipeline).
  
  ```
  pipeline {
    agent { label 'docker-custom-image' }
    environment {
          JAVA_HOME='/opt/java-se-8u44-ri'
          PATH = "$JAVA_HOME/bin/:${env.PATH}"
    }
    stages {
      stage ('build') {
        steps {
          echo "PATH is: ${env.PATH}"
        }
      }
    }
  }
  
  ```
  
  
  ---
  
  