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

Environment variables referencing other variables broken

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      This seems to have broken fairly recently. I have a global PATH environment variable defined in Jenkins as follows:

      PATH: /path/to/toolchain/bin:$PATH

      Freestyle jobs work with this. An older version of the durable task plugin also worked. After updating to the latest, this pipeline job:

      node('master', {
          echo 'env.PATH=' + env.PATH
          sh('env')
         })
      

      results in this output:

      [Pipeline] node
      Running on master in /var/lib/jenkins/workspace/pipeline bug
      [Pipeline] {
      [Pipeline] echo
      env.PATH=/path/to/toolchain/bin:$PATH
      [Pipeline] sh
      [pipeline bug] Running shell script
      nohup: failed to run command ‘sh’: No such file or directory
      [Pipeline] }
      [Pipeline] // node
      [Pipeline] End of Pipeline
      ERROR: script returned exit code -2
      Finished: FAILURE
      

        Attachments

          Issue Links

            Activity

            Hide
            apgray Andrew Gray added a comment -

            Disagree Dawid.  Having used Jenkins for 11 years.  Use the plugins as much as possible.

            Show
            apgray Andrew Gray added a comment - Disagree Dawid.  Having used Jenkins for 11 years.  Use the plugins as much as possible.
            Hide
            lyda Kevin Lyda added a comment -

            This is crazy. Is there no sane way to do this in a declarative pipeline?

            I would like to do this rather basic thing in a declarative pipeline in a Jenkins file:

             

            environment {
              GOPATH = "$WORKSPACE/gopath/bin"
              PATH = "$GOPATH/bin:$PATH"
            }
            

             

            But for some inexplicable reason we can't modify environment variables like one does in every single other utility in the world? Fine, I'll write a script. But clearly looking at buildbot keeps being shoved forcibly up my priority list.

            Show
            lyda Kevin Lyda added a comment - This is crazy. Is there no sane way to do this in a declarative pipeline? I would like to do this rather basic thing in a declarative pipeline in a Jenkins file:   environment {   GOPATH = "$WORKSPACE/gopath/bin"   PATH = "$GOPATH/bin:$PATH" }   But for some inexplicable reason we can't modify environment variables like one does in every single other utility in the world? Fine, I'll write a script. But clearly looking at buildbot keeps being shoved forcibly up my priority list.
            Hide
            oleg_nenashev Oleg Nenashev added a comment -

            Kevin Lyda EnvInject plugin does not support Pipeline, and there is no short-term plans to do so. Your comment is not related to this ticket IMHO, Declarative Pipeline has its own implementation. AFAIK there is a ticket for the case you raise (CC Andrew Bayer Sam Van Oort)

            Show
            oleg_nenashev Oleg Nenashev added a comment - Kevin Lyda EnvInject plugin does not support Pipeline, and there is no short-term plans to do so. Your comment is not related to this ticket IMHO, Declarative Pipeline has its own implementation. AFAIK there is a ticket for the case you raise (CC Andrew Bayer Sam Van Oort )
            Hide
            gruemaster Tobin Davis added a comment - - edited

            I am really confused by all of this.

            First, I'm running 2.138.2 LTS (I know, I need to update), with all of the latests plugin version for pipeline (and no EnvInject plugin).  I have tried the following, with no success:

            1st:

            environment {
              DCP_VERSION = "1.2-alpha"
              DCP_LOC = "/opt/dcp/${DCP_VERSION}"
              QUARTUS_HOME = "/opt/inteldevstack/intelFPGA_pro/quartus" 
              MTI_HOME = "/opt/altera/17.1/modelsim_ase"
              TBB_HOME = "/opt/intel/tbb"
              PATH = "${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin:${PATH}"
              LD_LIBRARY_PATH = '${LD_LIBRARY_PATH}:${TBB_HOME}/lib/intel64_lin/gcc4.7'
            }

            Produced this error:

            nohup: failed to run command 'sh': No such file or directory

            2nd (based on googling the sh command error)

            environment {
              DCP_VERSION = "1.2-alpha"
              DCP_LOC = "/opt/dcp/${DCP_VERSION}"
              QUARTUS_HOME = "/opt/inteldevstack/intelFPGA_pro/quartus" 
              MTI_HOME = "/opt/altera/17.1/modelsim_ase"
              TBB_HOME = "/opt/intel/tbb"
              PATH+EXTRA = "${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin"
              LD_LIBRARY_PATH = '${LD_LIBRARY_PATH}:${TBB_HOME}/lib/intel64_lin/gcc4.7'
            }

            Now I get this error:
            (PATH + EXTRA) is a binary expression, but it should be a variable expression at line: 11 column: 19. File: WorkflowScript @ line 11, column 19.
            PATH+EXTRA="${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin"

            Note that neither of these solutions are actually documented in the pipeline guide (https://jenkins.io/doc/book/pipeline/syntax/), and BOTH options are fully acceptable and copied from the built-in syntax generator.

            So, what is the right way to do this? I can't set global paths as a lot of these paths change depending on the job (for example, MTI_HOME will change depending on simulator used - future script development task)

             

            Update:  I got around the first issue by setting Jenkins global shell to /bin/bash.  Not cross platform, but works for now.

            Show
            gruemaster Tobin Davis added a comment - - edited I am really confused by all of this. First, I'm running 2.138.2 LTS (I know, I need to update), with all of the latests plugin version for pipeline (and no EnvInject plugin).  I have tried the following, with no success: 1st: environment {   DCP_VERSION = "1.2-alpha"   DCP_LOC = "/opt/dcp/${DCP_VERSION}"   QUARTUS_HOME = "/opt/inteldevstack/intelFPGA_pro/quartus"    MTI_HOME = "/opt/altera/17.1/modelsim_ase"   TBB_HOME = "/opt/intel/tbb"   PATH = "${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin:${PATH}"   LD_LIBRARY_PATH = '${LD_LIBRARY_PATH}:${TBB_HOME}/lib/intel64_lin/gcc4.7' } Produced this error: nohup: failed to run command 'sh': No such file or directory 2nd (based on googling the sh command error) environment {   DCP_VERSION = "1.2-alpha"   DCP_LOC = "/opt/dcp/${DCP_VERSION}"   QUARTUS_HOME = "/opt/inteldevstack/intelFPGA_pro/quartus"    MTI_HOME = "/opt/altera/17.1/modelsim_ase"   TBB_HOME = "/opt/intel/tbb"   PATH+EXTRA = "${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin"   LD_LIBRARY_PATH = '${LD_LIBRARY_PATH}:${TBB_HOME}/lib/intel64_lin/gcc4.7' } Now I get this error: (PATH + EXTRA) is a binary expression, but it should be a variable expression at line: 11 column: 19. File: WorkflowScript @ line 11, column 19. PATH+EXTRA="${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin" Note that neither of these solutions are actually documented in the pipeline guide ( https://jenkins.io/doc/book/pipeline/syntax/ ), and BOTH options are fully acceptable and copied from the built-in syntax generator. So, what is the right way to do this? I can't set global paths as a lot of these paths change depending on the job (for example, MTI_HOME will change depending on simulator used - future script development task)   Update:  I got around the first issue by setting Jenkins global shell to /bin/bash.  Not cross platform, but works for now.
            Hide
            jglick Jesse Glick added a comment -

            Tobin Davis the PATH+EXTRA system works for Scripted Pipeline. If it does not work for Declarative, please file a separate RFE in pipeline-model-definition-plugin. Workaround would I guess be something like (untested)

            environment {
              STUFF = "${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin"
            }
            // …
            steps {
              withEnv(["PATH+EXTRA=$STUFF"]) {
                sh 'whatever'
              }
            }
            
            Show
            jglick Jesse Glick added a comment - Tobin Davis the PATH+EXTRA system works for Scripted Pipeline. If it does not work for Declarative, please file a separate RFE in pipeline-model-definition-plugin . Workaround would I guess be something like (untested) environment { STUFF = "${MTI_HOME}/linux:${MTI_HOME}/bin:${QUARTUS_HOME}/bin:${DCP_LOC}/bin" } // … steps { withEnv([ "PATH+EXTRA=$STUFF" ]) { sh 'whatever' } }

              People

              • Assignee:
                Unassigned
                Reporter:
                jtatum James Tatum
              • Votes:
                22 Vote for this issue
                Watchers:
                47 Start watching this issue

                Dates

                • Created:
                  Updated: