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

0 views
Skip to first unread message

blanca.borro@bde.es (JIRA)

unread,
Feb 20, 2018, 3:28:04 AM2/20/18
to jenkinsc...@googlegroups.com
Blanca Borro Escribano reopened an issue
 

Good morning, it seems this is happening to me again in Jenkins ver. 2.73.2, no matter what value i try to set to the PATH variable it always get the same value:

echo PATH is: /sbin:/usr/sbin:/bin:/usr/bin

the other variables set in the environment are being set correctly, only path is not being set.

 

 

Jenkins / Bug JENKINS-45916
Path is not getting set correctly in pipeline when there is a variable present
Change By: Blanca Borro Escribano
Resolution: Fixed
Status: Resolved Reopened
Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.3.0#73011-sha1:3c73d0e)
Atlassian logo

andrew.bayer@gmail.com (JIRA)

unread,
Apr 17, 2018, 5:29:02 PM4/17/18
to jenkinsc...@googlegroups.com

redeamer@gmx.net (JIRA)

unread,
May 11, 2018, 9:49:02 AM5/11/18
to jenkinsc...@googlegroups.com

Hi, I'm not sure if this is was Blanca Borro Escribano was referencing:

pipeline {
    agent {
        docker {
            image 'alpine:latest'
        }
    }

    environment {
        PATHX = "${env.WORKSPACE}:${env.PATH}"
        PATH = "${env.WORKSPACE}:${env.PATH}"
    }

    stages {
        stage('Test') {
            steps {
                echo "PATH : ${env.PATH}"
                echo "PATHX: ${env.PATHX}"
                sh "printenv | grep PATH"
            }
        }
    }
}

Which prints:

[Pipeline] echo PATH : /home/catroid/jenkins_slave2_emulator/workspace/test:/usr/local/bin:/usr/bin:/bin:/usr/games
[Pipeline] echo PATHX: /home/catroid/jenkins_slave2_emulator/workspace/test:/home/catroid/jenkins_slave2_emulator/workspace/test:/usr/local/bin:/usr/bin:/bin:/usr/games
[Pipeline] sh
[test] Running shell script
+ printenv
+ grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CLASSPATH=
PATHX=/home/catroid/jenkins_slave2_emulator/workspace/test:/home/catroid/jenkins_slave2_emulator/workspace/test:/usr/local/bin:/usr/bin:/bin:/usr/games

So both variables are expanded correctly, but PATH is not passed to the environment of sh. Could also be a problem in the sh step.

I'm also confused with the order of expansion: whether (in the environment stage) i put PATHX first or second, it seems that PATH gets always set first, because PATHX has the WORKSPACE variable content always prefixed twice

blanca.borro@bde.es (JIRA)

unread,
May 12, 2018, 3:13:02 PM5/12/18
to jenkinsc...@googlegroups.com

Hello, i managed to solve the problem. I think the problem was due to lack of knowledge from my part.

anthony.communier@gmail.com (JIRA)

unread,
May 20, 2018, 5:35:02 PM5/20/18
to jenkinsc...@googlegroups.com

Blanca Borro Escribano : I have the same issue , could you explain how you solve the problem ?

blanca.borro@bde.es (JIRA)

unread,
May 22, 2018, 3:29:03 AM5/22/18
to jenkinsc...@googlegroups.com

Anthony Communier the problem i had was that i was mixing the use of declarative pipeline with scripting pipeline. I finally used declarative pipeline for everything and found no problem.

redeamer@gmx.net (JIRA)

unread,
May 22, 2018, 1:42:02 PM5/22/18
to jenkinsc...@googlegroups.com
Michael Musenbrock edited a comment on Bug JENKINS-45916
Hi, I'm not sure if this is was [~bbborro] was referencing:
{code:java}

pipeline {
    agent {
        docker {
            image 'alpine:latest'
        }
    }

    environment {
        PATHX = "${env.WORKSPACE}:${env.PATH}"
        PATH = "${env.WORKSPACE}:${env.PATH}"
    }

    stages {
        stage('Test') {
            steps {
                echo "PATH : ${env.PATH}"
                echo "PATHX: ${env.PATHX}"
                sh "printenv | grep PATH"
            }
        }
    }
}{code}
Which prints:
{noformat}
[Pipeline] echo PATH : /
home jenkins_slave / catroid/jenkins_slave2_emulator/ workspace/test:/usr/local/bin:/usr/bin:/bin:/usr/games
[Pipeline] echo PATHX: /
home jenkins_slave / catroid/jenkins_slave2_emulator/ workspace/test:/ home jenkins_slave / catroid/jenkins_slave2_emulator/ workspace/test:/usr/local/bin:/usr/bin:/bin:/usr/games

[Pipeline] sh
[test] Running shell script
+ printenv
+ grep PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
CLASSPATH=
PATHX=/ home jenkins_slave / catroid/jenkins_slave2_emulator/ workspace/test:/ home jenkins_slave / catroid/jenkins_slave2_emulator/ workspace/test:/usr/local/bin:/usr/bin:/bin:/usr/games
{noformat}

So both variables are expanded correctly, but PATH is not passed to the environment of sh. Could also be a problem in the sh step.

I'm also confused with the order of expansion: whether (in the environment stage) i put PATHX first or second, it seems that PATH gets always set first, because PATHX has the WORKSPACE variable content always prefixed twice

andrew.bayer@gmail.com (JIRA)

unread,
Nov 15, 2018, 12:03:02 PM11/15/18
to jenkinsc...@googlegroups.com
Change By: Andrew Bayer
Status: Reopened Fixed but Unreleased
Resolution: Fixed
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

daniel.sorensen@clarivate.com (JIRA)

unread,
Nov 8, 2019, 10:32:03 AM11/8/19
to jenkinsc...@googlegroups.com
Daniel Sorensen updated an issue
Change By: Daniel Sorensen
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.
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

daniel.sorensen@clarivate.com (JIRA)

unread,
Nov 8, 2019, 10:33:03 AM11/8/19
to jenkinsc...@googlegroups.com

ilatypov@yahoo.ca (JIRA)

unread,
Mar 12, 2020, 3:41:02 PM3/12/20
to jenkinsc...@googlegroups.com
Ilguiz Latypov commented on Bug JENKINS-45916
 
Re: Path is not getting set correctly in pipeline when there is a variable present

What does that mean for the mere mortals?  Is "steps" or "sh" the thing to avoid?

This message was sent by Atlassian Jira (v7.13.12#713012-sha1:6e07c38)
Atlassian logo

ilatypov@yahoo.ca (JIRA)

unread,
Mar 12, 2020, 3:48:05 PM3/12/20
to jenkinsc...@googlegroups.com

Never mind, I see the magic recipe.  I still don't know the exact difference between "declarative" and "scripting", but I am mortal as well....

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'
  }
}

https://issues.jenkins-ci.org/browse/JENKINS-41339?focusedCommentId=357645&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-357645

 

ilatypov@yahoo.ca (JIRA)

unread,
Mar 17, 2020, 1:11:03 AM3/17/20
to jenkinsc...@googlegroups.com

I figured the original issue appears fixed in Jenkins 2.226 and current plugins. Sorry I just noticed Andrew Bayer's fix in this ticket.

```groovy
pipeline {
agent

{ label 'linux' }

environment

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

stages {
stage ('build') {
steps {
echo "PATH=$PATH"

echo "env.PATH=${env.PATH}"
sh "export -p | grep PATH"
}
}
}
}
```

```text
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/jenkins_home/workspace/System/Test_JENKINS-45916
[Pipeline] {
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline]

{ (build) [Pipeline] echo PATH=/a/new/bin:/usr/local/nvm/versions/node/v10.15.0/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [Pipeline] echo env.PATH=/a/new/bin:/usr/local/nvm/versions/node/v10.15.0/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin [Pipeline] sh + export -p + grep PATH declare -x GEM_PATH="file:/var/jenkins_home/plugins/ruby-runtime/WEB-INF/lib/stapler-jruby-1.209.jar!/gem/" declare -x PATH="/a/new/bin:/usr/local/nvm/versions/node/v10.15.0/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" [Pipeline] }

[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
```

ilatypov@yahoo.ca (JIRA)

unread,
Mar 17, 2020, 1:12:03 AM3/17/20
to jenkinsc...@googlegroups.com
Ilguiz Latypov edited a comment on Bug JENKINS-45916
I figured the original issue appears fixed in Jenkins 2.226 and current plugins.  Sorry I just noticed Andrew Bayer's fix in this ticket.

```

{code:
groovy }
pipeline {
    agent {
        label 'linux'
    }

    environment {
        PATH="/a/new/bin:$PATH"
   }
   stages {
        stage ('build') {
            steps {
                echo "PATH=$PATH"
                echo "env.PATH=${env.PATH}"
                sh "export -p | grep PATH"
            }
        }
    }
}
``` {code}

``` {code: text }
```
{code}

ilatypov@yahoo.ca (JIRA)

unread,
Mar 17, 2020, 1:12:05 AM3/17/20
to jenkinsc...@googlegroups.com
Ilguiz Latypov edited a comment on Bug JENKINS-45916
I figured the original issue appears fixed in Jenkins 2.226 and current plugins.  Sorry I just noticed Andrew Bayer's fix in this ticket.


{code:groovy}
pipeline {
    agent {
        label 'linux'
    }

    environment {
        PATH="/a/new/bin:$PATH"
   }
   stages {
        stage ('build') {
            steps {
                echo "PATH=$PATH"
                echo "env.PATH=${env.PATH}"
                sh "export -p | grep PATH"
            }
        }
    }
}
{code}

{code: text none }

ilatypov@yahoo.ca (JIRA)

unread,
Mar 17, 2020, 1:13:03 AM3/17/20
to jenkinsc...@googlegroups.com
Ilguiz Latypov edited a comment on Bug JENKINS-45916
I figured the original issue appears fixed in , and I am just confirming this for Jenkins 2.226 and current plugins.  Sorry I just noticed Andrew Bayer's fix in this ticket.


{code:groovy}
pipeline {
    agent {
        label 'linux'
    }

    environment {
        PATH="/a/new/bin:$PATH"
   }
   stages {
        stage ('build') {
            steps {
                echo "PATH=$PATH"
                echo "env.PATH=${env.PATH}"
                sh "export -p | grep PATH"
            }
        }
    }
}
{code}

{code:none}

ilatypov@yahoo.ca (JIRA)

unread,
Mar 20, 2020, 5:58:02 PM3/20/20
to jenkinsc...@googlegroups.com

The environment clause appears to be ignored by plugins executing code such as the following,

EnvVars vars = build.getEnvironment(listener); 

My current work-around is to define hard-coded default values for the pipeline "parameters", even for the agent "master" which runs on the same machine with the server...

    agent {
        label 'master'
    }
    
    parameters {
        string(name: 'FORTIFY_HOME', defaultValue: "/MYTOOLDIR/fortify", 
            description: 'A work-around to the plugin using FORTIFY_HOME of the Jenkins server instead of that of the agent')
        string(name: 'PATH', defaultValue: 
            "/MYTOOLDIR/fortify/bin:/usr/local/FOO/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", 
            description: 'A work-around to the plugin using PATH of the Jenkins server instead of that of the agent')
    }

I wish Jenkins in general its plugins in particular gave precendence to the agent's environment. I did not try to find the exact API to fetch that in the context of the plugin running on the server but aiming the given "agent".

ilatypov@yahoo.ca (JIRA)

unread,
Mar 20, 2020, 6:25:02 PM3/20/20
to jenkinsc...@googlegroups.com
Ilguiz Latypov edited a comment on Bug JENKINS-45916
The environment clause appears to be ignored by plugins executing code such as the following,
{code:groovy}
EnvVars vars = build.getEnvironment(listener);
{code}

My current work-around is to define hard-coded default values for the pipeline "parameters", even for the agent "master" which runs on the same machine with the server.
  However, this breaks Jenkins server's own checkout of the project using Git from PATH . .

{code:groovy}

    agent {
        label 'master'
    }
    
    parameters {
        string(name: 'FORTIFY_HOME', defaultValue: "/MYTOOLDIR/fortify",
            description: 'A work-around to the plugin using FORTIFY_HOME of the Jenkins server instead of that of the agent')
        string(name: 'PATH', defaultValue:
            "/MYTOOLDIR/fortify/bin:/usr/local/FOO/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            description: 'A work-around to the plugin using PATH of the Jenkins server instead of that of the agent')
    }
{code}


I wish Jenkins in general its plugins in particular gave precendence to the agent's environment. I did not try to find the exact API to fetch that in the context of the plugin running on the server but aiming the given "agent".

ilatypov@yahoo.ca (JIRA)

unread,
Mar 20, 2020, 6:27:03 PM3/20/20
to jenkinsc...@googlegroups.com
Ilguiz Latypov edited a comment on Bug JENKINS-45916
The environment clause appears to be ignored by plugins executing code such as the following,
{code:groovy}
EnvVars vars = build.getEnvironment(listener);
{code}

My current work-around is to define hard-coded default values for the pipeline "parameters", even for the agent "master" which runs on the same machine with the server.   However, this breaks   (If Jenkins server 's needs to run its own checkout of , say, a pipeline library, then it will fail to use Git on the project server using Git from the agent-targeting PATH ) .


{code:groovy}
    agent {
        label 'master'
    }
    
    parameters {
        string(name: 'FORTIFY_HOME', defaultValue: "/MYTOOLDIR/fortify",
            description: 'A work-around to the plugin using FORTIFY_HOME of the Jenkins server instead of that of the agent')
        string(name: 'PATH', defaultValue:
            "/MYTOOLDIR/fortify/bin:/usr/local/FOO/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
            description: 'A work-around to the plugin using PATH of the Jenkins server instead of that of the agent')
    }
{code}

I wish Jenkins in general its plugins in particular gave precendence to the agent's environment. I did not try to find the exact API to fetch that in the context of the plugin running on the server but aiming the given "agent".
Reply all
Reply to author
Forward
0 new messages