You may not need to go the docker agent route, especially of you particular JDK does not have an image.
JDK for JENKINS itself
When you run Jenkins, it runs on the Java you specify, typically what's available on the command line (ie: java -jar jenkins.war
).
When you launch a standard linux agent (SSH Build Agents (aka:ssh-slaves) plugin), by default agents launch using the available JDK/JRE. However, the plugin also allows you to specify a custom JavaPath and runtime options.
This above is the "default" or "System" JDK available to your jobs and steps running on the agent. Note that Jenkins 2.x supports only Java 8 and Java 11. Java 11 is supported in Jenkins 2.164.1 and as of the August releases, Docker images for Controllers (master) use Java 11 by default as noted:
Jenkins 2.306 running as jenkins/jenkins:latest uses Java 8. When Jenkins 2.307 or later is run with jenkins/jenkins:latest, it will use Java 11
Jenkins 2.289.3 running as jenkins/jenkins:lts uses Java 8. When Jenkins 2.303.1 or later is run with jenkins/jenkins:lts, it will use Java 11
JDK for JENKINS Jobs
Jenkins allows multiple tools, including jdk, NodeJS, Docker, ant, gradle, maven, etc. versions to be made available to your build. They must be pre-configured configured under Manage Jenkins → Global Tool Configuration ( ${JENKINS_URL}/configureTools/
).
The Jenkins "Managing Tools" documentation is lacking at this time, and the Pipeline documentation provides an limited explanation. Cloudbees explains a bit more. This old S/O answer explains the basics, incl duding the often overlooked "JDK" [ Default (System) ], located at the end of the "General" section of your job.
Once you've configured Global defaults, There's also an option to override the default location of the various instances on a per Node level, as noted in this S/O answer.
Whatever options are chosen, that overrides the JAVA_HOME (ANT_HOME, M2_HOME, etc.) made available to your job steps (Job overrides node overrides Global). For pipeline jobs, you can specify that using the "tools" option inside the pipeline block or a stage block, eg:
tools {
jdk 'jdk1.8'
}
We have multiple versions (7/8/11) of Oracle JDK, JRockit, OpenJDK Hotspot and OpenJ9 and use the Node level Tool installations to override the installed path, for example on Win boxes.
There's also extra / custom Tool installer plugins which extend this flexible Tool Mgmt to other tools.
For completeness, you can also use the Environment Injector plugin to override environment variables, including the JAVA_HOME for either the whole job or starting from a specific step.