I'm just getting started with Jenkins, and specifically i'm testing out a project that uses JDK8, and can't be upgraded to JDK11.
Now Jenkins as of July 2022 uses JDK11 internally, and I'm unsure how to get it to talk to an agent that uses JDK8, in order to build my project on said agent.
I'm using this guide, and i'm going down the jnlp route, so i'm spinning up a container per job (it's a freestyle job for now), using the jenkins/jnlp-slave:latest-jdk11 image, which seems to work fine. However when I switch to the jenkins/jnlp-slave:latest
image (which uses JDK8), the container is unable to talk to Jenkins and I get this:
Inbound agent connected from 192.168.1.1/192.168.1.1:52636
java.lang.UnsupportedClassVersionError: hudson/slaves/SlaveComputer$SlaveVersion has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.lang.ClassLoader.defineClass(ClassLoader.java:635)
at hudson.remoting.RemoteClassLoader.loadClassFile(RemoteClassLoader.java:453)
Which implies Jenkins on JDK11 won't talk to an agent running JNLP JDK8. Now normally i'd know to just upgrade my JDK version, but that won't work here as my project specifically needs to build on JDK8.
How can I best resolve this? Modify the JDK8 docker image to use JDK11 to begin with but then switch on the fly via updating my PATH & JAVA_HOME to JDK8 when it comes to actually building my project?
Ideally i'd like to be able to build projects using either JDK8 or JDK11, depending on the docker image I pick for them.