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

Path is not getting set correctly in pipeline when there is a variable present

      After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

       

          environment

      {         PATH="/a/new/bin:$PATH"    }

       

      The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

      pipeline

      {       agent

      {  label 'docker'    }

          environment {
              PATH="/a/new/bin:${env.SCM_HOME}:$PATH"
              SCM_HOME="${env.SCM_HOME}"
         }
        stages {
          stage ('build') {
            steps

      {         echo "PATH=$PATH"         echo "SCM_HOME=$SCM_HOME"       }

          }
        }
      }

       

      OUTPUT:

       
      [Pipeline] {

      [Pipeline] withEnv

      [Pipeline] {

      [Pipeline] stage

      [Pipeline] { (build)

      [Pipeline] echoPATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

      [Pipeline] echoSCM_HOME=/usr/local/bin/scmtools/

      [Pipeline] }

      [Pipeline] // stage

      [Pipeline] }

      [Pipeline] // withEnv

      [Pipeline] }

      [Pipeline] // node

      [Pipeline] End of PipelineFinished: SUCCESS
       

       

      Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.

          [JENKINS-45916] Path is not getting set correctly in pipeline when there is a variable present

          James Murphy created issue -
          James Murphy made changes -
          Description Original: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment \{
                  PATH="/a/new/bin:$PATH"
             }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline \{
                agent \{  label 'docker'    }
              environment \{
                  PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH"
                  SCM_HOME="$\{env.SCM_HOME}"
             }
            stages \{
              stage ('build') \{
                steps \{
                  echo "PATH=$PATH"
                  echo "SCM_HOME=$SCM_HOME"
                }
              }
            }
          }

           

          OUTPUT:



           
          {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] withEnv{color}{color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] stage{color}{color:#9a9999}[Pipeline] \{ (build){color}{color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin{color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/{color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // stage{color}{color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // withEnv{color}{color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // node{color}{color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
           

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          New: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment \{
                   PATH="/a/new/bin:$PATH"
              }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline \{
                 agent \{  label 'docker'    }
               environment \{
                   PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH"
                   SCM_HOME="$\{env.SCM_HOME}"
              }
             stages \{
               stage ('build') \{
                 steps \{
                   echo "PATH=$PATH"
                   echo "SCM_HOME=$SCM_HOME"
                 }
               }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] \{ (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}{color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          James Murphy made changes -
          Description Original: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment \{
                   PATH="/a/new/bin:$PATH"
              }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline \{
                 agent \{  label 'docker'    }
               environment \{
                   PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH"
                   SCM_HOME="$\{env.SCM_HOME}"
              }
             stages \{
               stage ('build') \{
                 steps \{
                   echo "PATH=$PATH"
                   echo "SCM_HOME=$SCM_HOME"
                 }
               }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] \{{color}{color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] \{ (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}{color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}{color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          New: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment \{
                   PATH="/a/new/bin:$PATH"
              }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline \{
                 agent \{  label 'docker'    }
               environment \{
                   PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH"
                   SCM_HOME="$\{env.SCM_HOME}"
              }
             stages \{
               stage ('build') \{
                 steps \{
                   echo "PATH=$PATH"
                   echo "SCM_HOME=$SCM_HOME"
                 }
               }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] \{{color}

          {color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] \{{color}

          {color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] \{ (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          Andrew Bayer made changes -
          Component/s New: pipeline-model-definition-plugin [ 21706 ]
          Component/s Original: pipeline [ 21692 ]
          Assignee New: Andrew Bayer [ abayer ]
          Labels Original: environment-variables jenkins pipeline New: declarative-variable-and-method-resolution environment-variables jenkins pipeline
          Andrew Bayer made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Andrew Bayer made changes -
          Link New: This issue depends on JENKINS-42753 [ JENKINS-42753 ]
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: In Progress [ 3 ] New: Resolved [ 5 ]
          Blanca Borro Escribano made changes -
          Resolution Original: Fixed [ 1 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]
          Andrew Bayer made changes -
          Resolution New: Fixed [ 1 ]
          Status Original: Reopened [ 4 ] New: Fixed but Unreleased [ 10203 ]
          Daniel Sorensen made changes -
          Description Original: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment \{
                   PATH="/a/new/bin:$PATH"
              }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline \{
                 agent \{  label 'docker'    }
               environment \{
                   PATH="/a/new/bin:$\{env.SCM_HOME}:$PATH"
                   SCM_HOME="$\{env.SCM_HOME}"
              }
             stages \{
               stage ('build') \{
                 steps \{
                   echo "PATH=$PATH"
                   echo "SCM_HOME=$SCM_HOME"
                 }
               }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] \{{color}

          {color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] \{{color}

          {color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] \{ (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          New: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment {
                   PATH="/a/new/bin:$PATH"
              }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline {
                 agent \{  label 'docker'    }
               environment {
                   PATH="/a/new/bin:${env.SCM_HOME}:$PATH"
                   SCM_HOME="${env.SCM_HOME}"
              }
             stages {
               stage ('build') {
                 steps {
                   echo "PATH=$PATH"
                   echo "SCM_HOME=$SCM_HOME"
                 }
               }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] {{color}

          {color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] {{color}

          {color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] { (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          Daniel Sorensen made changes -
          Description Original: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment {
                   PATH="/a/new/bin:$PATH"
              }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline {
                 agent \{  label 'docker'    }
               environment {
                   PATH="/a/new/bin:${env.SCM_HOME}:$PATH"
                   SCM_HOME="${env.SCM_HOME}"
              }
             stages {
               stage ('build') {
                 steps {
                   echo "PATH=$PATH"
                   echo "SCM_HOME=$SCM_HOME"
                 }
               }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] {{color}

          {color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] {{color}

          {color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] { (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.
          New: After upgrading to latest Pipeline version and it's dependencies (we also upgraded the blue ocean plugins but don't think that caused an issue here), we noticed that the PATH was not getting set in our Jenkins Pipeline Jobs. After debugging found that if I set PATH to a string inside the "environment" section, as such:

           

              environment

          {         PATH="/a/new/bin:$PATH"    }

           

          The PATH was updated successfully without any issues. However if I introduce a variable, the path does not get updated, and defaults to what is on the agent that runs the job. Example:

          pipeline

          {       agent \\{  label 'docker'    }

              environment {
                   PATH="/a/new/bin:${env.SCM_HOME}:$PATH"
                   SCM_HOME="${env.SCM_HOME}"
              }
             stages {
               stage ('build') {
                 steps

          {         echo "PATH=$PATH"         echo "SCM_HOME=$SCM_HOME"       }

              }
             }
           }

           

          OUTPUT:

           
           {color:#9a9999}[Pipeline] {{color}

          {color:#9a9999}[Pipeline] withEnv{color}

          {color:#9a9999}[Pipeline] {{color}

          {color:#9a9999}[Pipeline] stage{color}

          {color:#9a9999}[Pipeline] { (build){color}

          {color:#9a9999}[Pipeline] echo{color}PATH=/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin

          {color:#9a9999}[Pipeline] echo{color}SCM_HOME=/usr/local/bin/scmtools/

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // stage{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // withEnv{color}

          {color:#9a9999}[Pipeline] }{color}

          {color:#9a9999}[Pipeline] // node{color}

          {color:#9a9999}[Pipeline] End of Pipeline{color}Finished: SUCCESS
            

           

          Notice that SCM_HOME resolves fine outside of PATH and that /a/new/bin was not added to the path. However if I drop the variable it will set PATH fine.

            abayer Andrew Bayer
            jammurp James Murphy
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: