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

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

    XMLWordPrintable

Details

    Description

      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.

      Attachments

        Issue Links

          Activity

            jammurp James Murphy created issue -
            jammurp James Murphy made changes -
            Field Original Value New Value
            Description 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.
            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.
            jammurp James Murphy made changes -
            Description 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.
            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 made changes -
            Component/s pipeline-model-definition-plugin [ 21706 ]
            Component/s pipeline [ 21692 ]
            Assignee Andrew Bayer [ abayer ]
            Labels environment-variables jenkins pipeline declarative-variable-and-method-resolution environment-variables jenkins pipeline
            abayer Andrew Bayer made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            abayer Andrew Bayer made changes -
            Link This issue depends on JENKINS-42753 [ JENKINS-42753 ]
            abayer Andrew Bayer made changes -
            Resolution Fixed [ 1 ]
            Status In Progress [ 3 ] Resolved [ 5 ]
            bbborro Blanca Borro Escribano made changes -
            Resolution Fixed [ 1 ]
            Status Resolved [ 5 ] Reopened [ 4 ]
            abayer Andrew Bayer made changes -
            Resolution Fixed [ 1 ]
            Status Reopened [ 4 ] Fixed but Unreleased [ 10203 ]
            dsorensen Daniel Sorensen made changes -
            Description 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.
            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.
            dsorensen Daniel Sorensen made changes -
            Description 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.
            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.

            People

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

              Dates

                Created:
                Updated:
                Resolved: