Search code examples
javajenkinsjenkins-pluginsjenkins-pipeline

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

Solution

  • 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