Pipeline build: Build node not using JDK from Global Tool Configuration

1,787 views
Skip to first unread message

ST

unread,
Aug 4, 2017, 10:48:47 AM8/4/17
to Jenkins Users
I have a Jenkinsfile pipeline build that uses our maven project. I also have configured latest jdk8 (1.8.0_144) in the Global Tool Configuration. When building the project on master node, the correct JDK is picked up:
15:11:49 + /export/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.3.x/bin/mvn --batch-mode --show-version [more maven args...]
15:11:49 Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
15:11:49 Maven home: /export/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.3.x
15:11:49 Java version: 1.8.0_144, vendor: Oracle Corporation
15:11:49 Java home: /export/jenkins/tools/hudson.model.JDK/jdk8/jre
15:11:49 Default locale: en_US, platform encoding: UTF-8
15:11:49 OS name: "linux", version: "3.10.0-514.26.2.el7.x86_64", arch: "amd64", family: "unix"


However when trying to build the same project on another build node, the build uses the default JDK installed on the build node:



The Jenkins slave nodes are configured as

ST

unread,
Aug 4, 2017, 10:53:11 AM8/4/17
to Jenkins Users
(sorry, email got sent too early, nasty default shortcuts)

However when trying to build the same project on another build node, the build uses the system-default JDK installed on the build node:

16:22:59 + /export/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.3.x/bin/mvn --batch-mode --show-version [more maven args...]
16:22:59 Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T17:41:47+01:00)
16:22:59 Maven home: /export/jenkins/tools/hudson.tasks.Maven_MavenInstallation/maven3.3.x
16:22:59 Java version: 1.8.0_141, vendor: Oracle Corporation
16:22:59 Java home: /usr/java/jdk1.8.0_141/jre
16:22:59 Default locale: en_US, platform encoding: UTF-8
16:22:59 OS name: "linux", version: "3.10.0-514.26.2.el7.x86_64", arch: "amd64", family: "unix"
The Global Tool Configuration seems to work fine for maven tool ,so why not for the jdk tool?

The Jenkins slave nodes are launched as "Launch slave agents via SSH", in case that is relevant.

Environment: Latest jenkins v3.72 with latest plugins, incl. SSH Slaves plugin v1.20.

Any ideas what could be wrong?
 stefan.

ST

unread,
Aug 4, 2017, 11:51:23 AM8/4/17
to Jenkins Users
Found a solution, here it is in case anyone else stumbles upon same problem:

In my Jenkinsfile I set up java through the global env variable:
String jdkHome = "${tool name: 'jdk8', type: 'hudson.model.JDK'}"
env.PATH = "${jdkHome}/bin:${env.PATH}"
And that is not recommended as per point 9 of this list: https://www.cloudbees.com/blog/top-10-best-practices-jenkins-pipeline-plugin

Using the withEnv{} wrapper instead worked perfectly:
withEnv(["JAVA_HOME=${ tool 'jdk8' }", "PATH+MAVEN=${tool 'maven3.3.x'}/bin:${env.JAVA_HOME}/bin"]) {
sh "mvn ..."
}

Best regards,
 stefan.
Reply all
Reply to author
Forward
0 new messages