I need to use a specific JDK version that is not available by default.
I need to use different JDK versions when building jobs.
I need to install on the agents the JDK version I need on demand.
If we have jobs that need to be built using different JDK versions, you would need to have these JDKs installed in your agents. Additionally, some JDK versions are not available to be used, as it is the case of JDK 11.
The Oracle Java SE Development Kit Installer Plugin will allow you to add new JDKs based in different versions from a dropdown menu. Once these JDKs are added from "Jenkins>Manage Jenkins>Global Tool Configuration", the jobs can be configured to install these packages in the agent where the build will be done. In this case, you will only need to select the version that matches your requirements.
If you already have a specific JDK installed in these machines, you can remove the "Install automatically" checkbox and directly indicate the JAVA_HOME path in the textbox that will appear after unchecking the "Install automatically" checkbox, as shown below:
Please note that you won’t be able to add a new item to this dropdown list, but you can certainly add a new JDK indicating the exact version you want to install. To do so, you can follow the below steps:
Add a new JDK under "Manage Jenkins>Global Tool Configuration>JDK".
Press the "Delete installer" button so you remove the "Install Oracle Java SE Development Kit from the website" dropdown.
Then, press "Add Installer" and select "Extract .zip/.tar.gz" from the dropdown menu.
3 new textboxes will appear, where you can enter the "Download URL for binary archive", which is the URL from which to download the tool in binary form (in ZIP or TAR.GZ format). You can also add an optional subdirectory of the downloaded and unpacked archive to use as the tool’s home directory. You can leave the "Label" field empty, as this may force the build to fail if this label doesn’t match on of the agent labels.
Please note that some download links may ask for authentication, which will be an issue during the install process, so you can double check the download URL you provide is not asking for credentials.
Another way to avoid this problem is placing the installer in a different server from which the download can be done (a Nexus server for instance).
Once this is setup, you can go to the job configuration and select one of these JDKs created before from the dropdown in the "General Tab".