Docker plugin: How to create build image still providing JDK8 with Jenkins 2.361.1?

I am looking for a way to migrate our Docker image used with Jenkins Docker plugin (GitHub - jenkinsci/docker-plugin: Jenkins Cloud Plugin that uses Docker) for providing JDK1.8 build support after the upgrade to the Jenkins 2.361.1 LTS version - which does not support Java8 for agents anymore.

Our current Docker image is based on adoptopenjdk/openjdk8, so

  • (1) people using the image could use javac and java from JDK 1.8 in their job pipelines
  • (2a) the agent launched in container using the image is running with JDK 1.8

Now with then new Jenkins version, (2a) ist not working anymore, because the agent in the container must run with JDK 11. So how can I change my Docker image that

  • (1) people using the image could use javac and java from JDK 1.8 in their job pipelines
  • (2b) the agent launched in container using the image is running with JDK 11
    ?

For the Connect method, I am using “Connect with SSH”. From the configuration page I can see that there is a property “JavaPath” available, but I could not find details on those property in the documentation: Is this property “JavaPath” (only) used for launching the agent in the container started from this template?

In this case, I might solve my problem this way:

  • additionally install JDK11 in my current JDK8 container, but leave defaults settings like JAVA_HOME to point to the JDK8 - for (1)
  • In Docker Cloud configuration of my Agent Template, point “JavaPath” to the JDK11 java executable in the image - for (2b)

Is this a possible solution for achieving (1) and (2b) in my image?

Thanks in advance,
Rainer

The controller and agent must run java 11. So that means java in the path and/or JAVA_HOME is set to jdk 11. Its recommended against running jobs on your controller itself, as it opens up people to be able to mess with jenkins itself.

Your jobs however can run whatever they want. You’d want the job to have PATH and JAVA_HOME env variables set to whatever jdk you want. I would recommend doing this in the configure node/agent screens, where you can override environmental variables.

But, to extend a docker image you would go

FROM jenkins/jenkins:lts # or other version
USER root
RUN .... whatever commands you want
USER jenkins

push docker image somewhere

1 Like

Thanks for the quick reply.

Let’s assume my image has both JDK8 and JDK11 installed and PATH and JAVA_HOME is set to JDK11 in Dockerfile; when I now use this image in my Docker Agent template and change JAVA_HOME and PATH in the environment settings of my “Configure Docker Agent Template” to JDK8, will this not “break” the agent launch to use those JDK8 settings?

Don’t change the definition of Java that is used by the agent to run the agent process. The agent process must be running the same Java version as the controller.

The Jenkins infrastructure team installs Java 8, Java 11, and Java 17 on all their container images. They run the agents using Java 11 that is inside the container image, but they configure the Java PATH for processes inside the container image based on the Java version that they need to run for the specific job.

You can either change the PATH for processes that are started on the agent without changing the Java version that runs the agent or you can use the Jenkins JDK tool installer to install the specific Java version that you need. It is uncommon to use the Jenkins JDK tool installer on an agent that is running in a container, but it is feasible.

If you want to learn more about Jenkins tool installers, consider this video:

1 Like

Many thanks for the info, I will check out the suggestions.

Rainer