Using different Java versions for agents and jobs


I have a Jenkins setup in my Kubernetes cluster, but my agents are outside. I connect agents using SSH, but I have one problem with Java.

For my project I must use java 8, however new Jenkins only supports 11 and 17. So in order to launch my node agent and connect, I must remove environment variable from the node settings, start my node, and then add JAVA_HOME jdk1.8.0_151 back to node environment variables. This is very inconvenient, since I have to manually do these steps if Jenkins or the agent get restarted.

I know I could add jdk1.8.0_151 environment variable to my job, but I think this is not very correct way, since I might have several nodes with different path to java8.

So, what may be the correct approach here?

You can configure the full path to java in the config (under advanced settings). This way you avoid that JAVA_HOME is used or java is taken from the path.

Thank you! I didn’t notice this field. It looks like the agent starts fine even with the env variable now.