4

My maven project have a hard dependency on jdk1.7. I have Jenkins(2.89.4) instance which has jdk 1.8. When I try to connect to slave which(specifying jdk 1.7 in this slave config), launch agent is failing with error below

   Starting slave process: cd "/jenkins" && /opt/jdk1.7.0_80/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:800)
        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

Launch agent is successful if this slave has JDK 1.8 installed. But, in this case, my maven build is failing as my maven project have a hard dependency on JDK 1.7.

I was wondering if there is a way to specify slave.jar which is compatible with jdk 1.7 in Jenkins instance

abhig
  • 840
  • 2
  • 12
  • 22

1 Answers1

3

Instead of reconfiguring the agent or messing around with the slave.jar, you can configure the job to use a specific version of the JDK.

One way to do that is by using the Jenkins Global Tool Configuration. Here's a basic walkthrough of setting it up with the Oracle JDK:

  1. Browse to http://JENKINS_HOME/configureTools/ (or Manage Jenkins -> ** Configure Global Tools**)
  2. Click on the JDK installations... button
  3. Click on Add JDK
  4. Input a name (something like JDK 1.7)
  5. Choose the appropriate version of the JDK from the dropdown list (like Java SE Development Kit 7u80)
  6. Check the box I agree to the Java SE Development Kit License Agreement
    • This box MUST be checked to perform the download automatically
  7. Click Save at the bottom of the page
  8. Browse to Configure your Maven project
  9. Look for the JDK dropdown in the general configuration section (will be shortly before Source Code Management)
  10. Choose your newly configured JDK 1.7 from the dropdown
  11. Save

Now, when you run your job, it will automatically download, install, and use the 7u80 JDK.

If you already have the JDK installed on the agent (or want to use something other than the Oracle JDK): back in the Global Tool Configuration section, there's an Add Installer button.

  • Label: Leave blank
  • Command: :
    • Yes, that's just the no-op colon. From the help: "The command will always be run, so it should be a quick no-op if the tool is already installed."
  • Tool Home: /opt/jdk1.7.0_80
bto
  • 1,619
  • 15
  • 23