Is there a way to change the java JRE a linux Jenkins server uses?
A Jenkins server is running under Java 1.7 on a linux machine and I need to change it to 1.8 so that I can run a specific plugin.
The Linux machine has a Java 1.8 JDK/JRE installed, but I cant find a way to tell the Jenkins server to use it? I've found guides on Windows servers how to do this, but nothing that relates or transfers to Linux Jenkins servers.
Is there a way to change the JRE used by the Jenkins server on linux?
Like a linux version of this: https://dzone.com/articles/make-jenkins-windows-service
On the Jenkins Main Page, to the Left click "Manage Jenkins." Access "Global Tool Configuration" menu, and under this menu there is a location about half way down that should say "JDK Installations." Click that button and it will open a new menu where you can add an alternate JDK. Once added, you go into the project you want to build and click "Configure." Again, about half way down will be a "JDK" drop down. The new JDK will now appear and you can select it to build your project.
However, if you mean you want the entire service to run from a different VM, that is a little trickier. Jenkins start script is written to try and "guess" your VM so it has easier installation across multiple Linux flavors. Find the start script (Red Hat RPM install places it in /etc/rc.d/init.d/jenkins) and read through it. You'll find a section labelled "candidates" and notice how the loop runs through the possible JVMs that might be on a system. You could edit this list to only be the VM you want to use and then stop/start to force it to use the VM you want. Make sure you copy the script before you edit it, just in case.
Depending on the distribution, you will have one of "/etc/sysconfig/jenkins" or "/etc/default/jenkins".
This will have a property to set the java home location. Usually all the options are commented out to show what the file can configure.
One way to accomplish this is editing the startup file: /etc/init.d/jenkins
.
The default is to just run java
, thus relying on what's in the PATH environment variable. You can specify a custom Java executable by editing the line:
JAVA=`type -p java`
to:
JAVA='/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java'
You must then run systemctl daemon-reload
in order for the changes to be picked up.
This is what I had to do in order to make Jenkins use Java 8 on a Ubuntu system with Java 11 set as the default. It was not acceptable for me to just apt remove openjdk-11-jdk-headless
or update-alternatives --config java
and choose Java 8 as the default. The caveat with editing the startup file is that it might be is overwritten every time Jenkins is updated.