2

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.

John Bergqvist
  • 852
  • 13
  • 38
  • I *think* since Jenkins agents communicate using serialization, you'll need Java 11 in your image. You can *also* have another JDK to actually build your stuff (i.e. the agent and the actual build don't have to use the same JDK), but I don't know the best way to set that up. – Joachim Sauer Jan 13 '23 at 11:17
  • @JoachimSauer Yeah, i've just noticed there's a global tool configuration part of Jenkins where I can pick different JDKs, so i'll have a look at that, but i'm not sure how i'd then communicate said JDK choice to the particular agents. – John Bergqvist Jan 13 '23 at 11:32
  • check your configuration following the video from official jenkins youtube channel https://www.youtube.com/watch?v=ymI02j-hqpU – Dmitriy Tarasevich Jan 13 '23 at 14:30
  • I think you have your answer, but to confirm... Jenkins agent must run 11/17, same as controller. A separate jdk can be configured via Global Tools and referenced on the jobs using `tools` `jdk`. Better to have it pre-installed in the image rather than continuously downloading and install when jobs needing it run (faster, less traffic, space, etc). – Ian W Jan 14 '23 at 07:43
  • @DmitriyTarasevich Thanks! I was hoping to move onto a pipeline job a bit later once i'd got a basic freestyle job up & running, but this does look like what I'd need. Thanks very much. – John Bergqvist Jan 14 '23 at 08:51

0 Answers0