JDK setting and JAVA_HOME not respected by Jenkins job

6,847 views
Skip to first unread message

Michael Pinnegar

unread,
Feb 20, 2017, 2:17:12 PM2/20/17
to job-dsl-plugin
My current setup is.

JDK 8 selected under the JDK options under the "General" tab.

Here is my groovy DSL script. I'm just executing it for diagnostic purposes.

println "java version" + System.getProperty("java.version")
println "runtime version" + Runtime.class.getPackage().getImplementationVersion()
def env = System.getenv()
//Print all the environment variables.

env.each{
println it
}

As you can see JAVA_HOME is not set from the groovy execution environment's point of view which causes problems when I have Java 8 compiled code on the classpath that needs to be loaded. How can I get this Groovy DSL plugin executing while respecting JDK 8?


18:41:05 Processing provided DSL script
18:41:05 java version1.7.0_121
18:41:05 runtime version1.7.0_121
18:41:05 JENKINS_HOME=/data/jenkins
18:41:05 JENKINS_UC=https://updates.jenkins-ci.org
18:41:05 LC_CTYPE=en_US.UTF-8
18:41:05 SHLVL=1
18:41:05 JAC_ENVIRONMENT=dev
18:41:05 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
18:41:05 JENKINS_AJP_PORT=-1
18:41:05 JAC_HOST=scifinder1
18:41:05 LOG_LEVEL=INFO
18:41:05 JENKINS_REF=/opt/jenkins
18:41:05 HOSTNAME=e55a4842db7a
18:41:05 PWD=/etc/service/jenkins
18:41:05 INITRD=no
18:41:05 _=/usr/bin/env
18:41:05 LANG=en_US.UTF-8
18:41:06 Finished: SUCCESS

Victor Martinez

unread,
Feb 20, 2017, 5:25:56 PM2/20/17
to job-dsl-plugin
Hi Michael,

Just to confirm, Have you declared the JDK 8 installation under the JDK configuration in the global settings of Jenkins? 

Cheers

Michael Pinnegar

unread,
Feb 20, 2017, 7:09:04 PM2/20/17
to job-dsl-plugin
I have indeed. The combo box for the jobs gets populated with options from the config in jenkins master.

Michael Pinnegar

unread,
Feb 20, 2017, 7:15:35 PM2/20/17
to job-dsl-plugin
Also this is what the environmental variables say when I look at the environmental variables for the job.

Environment variables

Name  ↓Value   
_/usr/bin/java
BUILD_CAUSEMANUALTRIGGER
BUILD_CAUSE_MANUALTRIGGERtrue
BUILD_DISPLAY_NAME#6
BUILD_ID6
BUILD_NUMBER6
BUILD_TAGjenkins-seed-6
EXECUTOR_NUMBER0
GRADLE_USER_HOME${WORKSPACE}/.gradle
HOME/home/sf16ci
HUDSON_HOME/data/jenkins
HUDSON_SERVER_COOKIE9015f71541b17a0d
JAVA_HOME/usr/lib/jvm/java-8-oracle
JENKINS_HOME/data/jenkins
JENKINS_SERVER_COOKIE9015f71541b17a0d
JOB_BASE_NAMEseed
JOB_NAMEseed
LANGen_US.UTF-8
LOGNAMEsf16ci
MAIL/var/mail/sf16ci
NLSPATH/usr/dt/lib/nls/msg/%L/%N.cat
NODE_LABELScode-review sf16ci-11 user:scioto-ci
NODE_NAMEsf16ci-11
OLDPWD/home/sf16ci
PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
PATH+JDK/usr/lib/jvm/java-8-oracle/bin
PWD/home/sf16ci/jenkins
ROOT_BUILD_CAUSEMANUALTRIGGER
ROOT_BUILD_CAUSE_MANUALTRIGGERtrue
SHELL/bin/bash
SHLVL1
SSH_CLIENT10.243.41.72 53059 22
SSH_CONNECTION10.243.41.72 53059 10.243.43.189 22
USERsf16ci
XFILESEARCHPATH/usr/dt/app-defaults/%L/Dt

Victor Martinez

unread,
Feb 21, 2017, 5:43:34 PM2/21/17
to job-dsl-plugin
I tried a simple JobDSL and it behaved as I expected, see the below details

Job config xml:
<project>
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties/>
<scm class="hudson.scm.NullSCM"/>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<jdk>jdk8</jdk>
<triggers/>
<concurrentBuild>false</concurrentBuild>
<builders>
<javaposse.jobdsl.plugin.ExecuteDslScripts plugin="job...@1.58">
<scriptText>
println "java version" + System.getProperty("java.version") println "runtime version" + Runtime.class.getPackage().getImplementationVersion() def env = System.getenv() //Print all the environment variables. env.each{ println it }
</scriptText>
<usingScriptText>true</usingScriptText>
<ignoreExisting>false</ignoreExisting>
<ignoreMissingFiles>false</ignoreMissingFiles>
<failOnMissingPlugin>false</failOnMissingPlugin>
<unstableOnDeprecation>false</unstableOnDeprecation>
<removedJobAction>IGNORE</removedJobAction>
<removedViewAction>IGNORE</removedViewAction>
<lookupStrategy>JENKINS_ROOT</lookupStrategy>
</javaposse.jobdsl.plugin.ExecuteDslScripts>
</builders>
<publishers/>
<buildWrappers/>
</project>


JDK definition (/var/jenkins_home/config.xml) which it's part of the global settings

 <jdks>


    <jdk>


      <name>jdk8</name>


      <home></home>


      <properties>


        <hudson.tools.InstallSourceProperty>


          <installers>


            <hudson.tools.JDKInstaller>


              <id>jdk-8u121-oth-JPR</id>


              <acceptLicense>true</acceptLicense>


            </hudson.tools.JDKInstaller>


          </installers>


        </hudson.tools.InstallSourceProperty>


      </properties>


    </jdk>


    <jdk>


      <name>jdk7</name>


      <home></home>


      <properties>


        <hudson.tools.InstallSourceProperty>


          <installers>


            <hudson.tools.JDKInstaller>


              <id>jdk-7u80-oth-JPR</id>


              <acceptLicense>true</acceptLicense>


            </hudson.tools.JDKInstaller>


          </installers>


        </hudson.tools.InstallSourceProperty>


      </properties>


    </jdk>


  </jdks>



Console output of the above jenkins job:
Building in workspace /var/jenkins_home/workspace/test
Installing JDK jdk-8u121-oth-JPR
Downloading JDK from http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz
Downloading 183246769 bytes
Installing /var/jenkins_home/tools/hudson.model.JDK/jdk8/jdk.sh
[jdk8] $ tar xvzf /var/jenkins_home/tools/hudson.model.JDK/jdk8/jdk.sh
...
jdk1.8.0_121/man/ja_JP.UTF-8/man1/jstat.1
Processing provided DSL script
java version1
.8.0_111-internal
runtime version1
.8.0_111-internal
PATH
=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin
COPY_REFERENCE_FILE_LOG
=/var/jenkins_home/copy_reference_file.log
JAVA_HOME
=/usr/lib/jvm/java-1.8-openjdk
JENKINS_UC
=https://updates.jenkins.io
TINI_SHA
=afbf8de8a63ce8e4f18cb3f34dfdbbd354af68a1
XFILESEARCHPATH
=/usr/dt/app-defaults/%L/Dt
JENKINS_VERSION
=2.32.2
LANG
=C.UTF-8
JENKINS_HOME
=/var/jenkins_home
HOSTNAME
=17241d9d6963
JAVA_ALPINE_VERSION
=8.111.14-r0
LD_LIBRARY_PATH
=/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-1.8-openjdk/jre/lib/amd64:/usr/lib/jvm/java-1.8-openjdk/jre/../lib/amd64
NLSPATH
=/usr/dt/lib/nls/msg/%L/%N.cat
JENKINS_SLAVE_AGENT_PORT
=50000
TINI_VERSION
=0.13.2
JAVA_VERSION
=8u111
PWD
=/
HOME=/
var/jenkins_home
SHLVL
=0
Finished: SUCCESS

I cannot reproduce your environment unfortunately, can you try your example by running a docker jenkins instance?

docker run -p 8080:8080 -p 50000:50000 jenkins:alpine


Cheers
Reply all
Reply to author
Forward
0 new messages