Jeremyapple
Jeremyapple

Reputation: 263

How do I force Jenkins 2.107.2 to use java-1.8.0 while launching an agent?

I am running into below error while launching an agent on my Jenkins 2.107.2 ,looks like this is a popular error and based on my homework it sounds like need to launch the agent using 1.8,I installed 1.8 and my /usr/lib/jvm folder looks like below,however when I launch the agent it still using java 1.7.0, how do I force Jenkins to launch the agent using 1.8?

/usr/lib/jvm

enter image description here

Error:

[05/02/18 10:17:59] [SSH] Starting sftp client.
[05/02/18 10:17:59] [SSH] Copying latest slave.jar...
[05/02/18 10:17:59] [SSH] Copied 762,466 bytes.
Expanded the channel window size to 4MB
[05/02/18 10:17:59] [SSH] Starting slave process: cd "/home/username" && /usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java  -jar slave.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: hudson/remoting/Launcher : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:803)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
Slave JVM has terminated. Exit code=1
[05/02/18 10:17:59] Launch failed - cleaning up connection
[05/02/18 10:17:59] [SSH] Connection closed

Upvotes: 4

Views: 3428

Answers (3)

G. Stevens
G. Stevens

Reputation: 127

For Windows, set the path to the Java executable you want to use in the jenkins-slave.xml file that gets created in the folder where the jenkins jar file is located.

For example:

<service>
  <id>jenkinsslave-C__jenkins</id>
  <name>Jenkins agent (jenkinsslave-C__jenkins)</name>
  <description>This service runs an agent for Jenkins automation server.</description>
  <executable>C:\Program Files\Java\jdk1.8.0_192\bin\java.exe</executable>

Upvotes: 0

BOC
BOC

Reputation: 1699

You can explicitly set the path to the java executable in the node launch configuration:

  1. Click on Manage Jenkins
  2. Click on Manage Nodes
  3. Click on the node you are trying to launch
  4. Click on configure
  5. Under Launch method there is a button labeled Advanced...; click it
  6. Find the option JavaPath and set it to the full path to the java executable you want to use; like:

    /usr/lib/jvm/java-1.8.0-openjdk-amd64/bin/java
    
  7. Save

  8. Relaunch the node

Upvotes: 3

pranay jain
pranay jain

Reputation: 372

You can set JAVA_HOME environment variable for the node by configuring it.

  1. Click on Manage Jenkins
  2. Click on Manage Nodes
  3. Select the Node on which you are running your build
  4. Click on configure.
  5. Add environment variable to it (JAVA_HOME)

Upvotes: 1

Related Questions