[JIRA] (JENKINS-58131) Jenkins master propagates environment variables to agents running a pipeline

7 views
Skip to first unread message

ilatypov@yahoo.ca (JIRA)

unread,
Jun 20, 2019, 7:34:03 PM6/20/19
to jenkinsc...@googlegroups.com
Ilguiz Latypov created an issue
 
Jenkins / Bug JENKINS-58131
Jenkins master propagates environment variables to agents running a pipeline
Issue Type: Bug Bug
Assignee: Unassigned
Components: pipeline
Created: 2019-06-20 23:33
Environment: 2.138.4
Priority: Minor Minor
Reporter: Ilguiz Latypov

I defined a Jenkins pipeline job with a Node parameter JENKINS_PARAM_RUN_NODE and the following script,

pipeline {
    agent none
    stages {
        stage('Run') {
            agent {
                label "${env.JENKINS_PARAM_RUN_NODE}"
            }
            steps {
                script {
                    echo 'Hello World'
                    sh 'export -p'
                }
            }
        }
    }
}

This showed JAVA_HOME of the Windows master despite selecting a MacOS agent.

...
+ export -p
...
export JAVA_HOME="C:\\Program Files\\Java\\jdk1.8.0_211"

Blanking the env variable exposes the MacOS agent's value,

            environment {
                JAVA_HOME = ''
            }
...
+ export -p
...
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home"

As an added bonus unrelated to Jenkins, MacOS's /usr/bin/java seems to interpret the unexpected Windows notation in JAVA_HOME by selecting the latest installed (I suppose) java.home,

type -a java
java -version
jh=$(java -XshowSettings:properties 2>&1 | sed -ne 's/^[[:space:]]*java\.home = \(.*\)/\1/p')
echo "java.home=\"${jh}\""
+ type -a java
java is /usr/bin/java
+ java -version
java version "10.0.2" 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
++ java -XshowSettings:properties
++ sed -ne 's/^[[:space:]]*java\.home = \(.*\)/\1/p'
+ jh=/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home
+ echo 'java.home="/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home"'
java.home="/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home"

I do not expect JAVA_HOME of master to override the agent's environment. As for the blanking env var work-around, I am not sure if this agrees with the expected semantics of the "environment" DSL clause because instead of unsetting the variable, it appears to expose the agent's variable.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d)

ilatypov@yahoo.ca (JIRA)

unread,
Jun 20, 2019, 7:35:02 PM6/20/19
to jenkinsc...@googlegroups.com
Ilguiz Latypov commented on Bug JENKINS-58131
 
Re: Jenkins master propagates environment variables to agents running a pipeline

Setting agent at the top of the pipeline DSL rather than in its stage produced the same outputs.

ilatypov@yahoo.ca (JIRA)

unread,
Jun 26, 2019, 5:14:02 PM6/26/19
to jenkinsc...@googlegroups.com

Thanks to my colleague I saw the Jenkins machine's configuration UI page (which was not available to me) and noticed the "Tool locations" thing which selected some Java version option probably defined in the Jenkins system configuration.  I am guessing this was the root cause of the bug.  The "tool locations" drop-down in computer configuration should account for major OS differences such as directory notation in JAVA_HOME for Windows and MacOS.

 

ilatypov@yahoo.ca (JIRA)

unread,
Jun 26, 2019, 5:16:02 PM6/26/19
to jenkinsc...@googlegroups.com
Ilguiz Latypov edited a comment on Bug JENKINS-58131
Thanks to my colleague I saw the Jenkins machine's configuration UI page (which was not available to me) and noticed the "Tool locations" thing which selected some Java version option probably defined in the Jenkins system configuration.  I am guessing this was the root cause of the bug.  The "tool locations" drop-down in computer configuration should account for major OS differences such as directory notation in JAVA_HOME for Windows and MacOS.   The system configuration should recognize this chance and offer at least two versions of each environment variable to be specified.  Selecting the respective option in the computer configuration will automatically choose one of the two depending on the computer's OS.

 
Reply all
Reply to author
Forward
0 new messages