Tien Dung Tran
Tien Dung Tran

Reputation: 1209

Upgrading Jenkins Java version from 8 to 11

I'd like to upgrade java from 8 to 11 as recommended for Jenkins 2.303.1, I'm reading the guide in https://www.jenkins.io/doc/administration/requirements/upgrade-java-guidelines/, but I don't know what to do in step:

Use a package manager to install the new JVM. Make sure the default JVM is the newly installed version. If it is not, use the correct java command in the Jenkins startup scripts (/etc/default/jenkins or /etc/init.d/jenkins).

does it mean install Java 11 and set java 11 is default one?

Upvotes: 2

Views: 13598

Answers (7)

VonC
VonC

Reputation: 1323793

Q4 2023: "Introducing the 2 + 2 + 2 Java support plan "

Jenkins 2.426.1 LTS will support Java 11, 17, and 21.

In Fall 2024, Jenkins will require Java 17 or 21 and drop support for Java 11.
Thereafter, Jenkins will support each Java LTS release for approximately four years; i.e., Jenkins will support two Java LTS releases at any given time.

https://www.jenkins.io/images/post-images/2023/11/06/introducing-2-2-2-java-support-plan-figure1.svg

  • 2023-11-15: Jenkins 2.426.1 LTS will support Java 11, 17, and 21.
  • 2024-11-15: Jenkins LTS will require Java 17 or 21 and drop support for Java 11.

Thereafter, the 2 + 2 + 2 support plan will take effect as described above.


Note: since June 2022, you do not have a choice anymore.

JDK 11 will need to be the one running Jenkins.
It does not have to be the "default" on your system. Only the one selected in the command use to run Jenkins.

Jenkins requires Java 11 (Basil Crow)

Beginning with Jenkins 2.357 (released on June 28, 2022) and the forthcoming September LTS release, Jenkins requires Java 11.

Additionally, beginning with Jenkins 2.355 (released on June 14, 2022) and Jenkins 2.346.1 LTS (released on June 22, 2022), Jenkins supports Java 17.

Plugins have already been prepared in JENKINS-68446.
Use the Plugin Manager to upgrade all plugins before and after upgrading to Jenkins 2.357.

Warning regarding JAXB

Prior to Java 11, Java Architecture for XML Binding (JAXB) was part of the Java Platform, and one could use it without adding a third-party dependency.
Beginning with Java 11, JAXB is no longer a part of the Java Platform and requires adding a third-party dependency.

Thanks to work done several years ago by Baptiste Mathus and others, a JAXB Jenkins plugin is available, which provides the JAXB library to Jenkins plugins in the form of a plugin-to-plugin dependency.

The vast majority of plugins have already been prepared to support Java 11 via the JAXB plugin in JENKINS-68446.
Jenkins users need only upgrade plugins to compatible versions as documented in the Released As field in Jira.

It is critical to use the Plugin Manager to upgrade all plugins before and after upgrading to Jenkins 2.357.
Failure to upgrade plugins to compatible versions may result in ClassNotFoundException, NoClassDefFoundError, or other low-level Java errors.

Upgrade

Docker

The official Jenkins Docker images have been based on Java 11 for many months, with Java 8 available as a fallback and Java 17 available in preview mode.

Beginning with Jenkins 2.357, the Java 8 images will be retired and the Java 17 images will transition from preview to general availability (GA). Users of the official Jenkins Docker images need not install or configure Java on their own, as it comes preinstalled in the image.

OS packages

Users of the official Jenkins OS packages for Debian, Red Hat, and SUSE Linux distributions should note that these packages are agnostic to the Java vendor. > In other words, you must bring your own Java package. One straightforward way to do this is to install Java 11 from your Linux distribution, as described on the package download site

Recommenced Garbage collection options

-XX:+AlwaysPreTouch
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=${PATH}
-XX:+UseG1GC
-XX:+UseStringDeduplication
-XX:+ParallelRefProcEnabled
-XX:+DisableExplicitGC
-XX:+UnlockDiagnosticVMOptions
-XX:+UnlockExperimentalVMOptions
-Xlog:gc*=info,gc+heap=debug,gc+ref*=debug,gc+ergo*=trace,gc+age*=trace:file=${PATH}/gc.log:utctime,pid,level,tags:filecount=2,filesize=100M
-XX:ErrorFile=${PATH}/hs_err_%p.log
-XX:+LogVMOutput
-XX:LogFile=${PATH}/jvm.log

Agents

For best results, it is recommended to run agents with the same version of Java as the version used on the controller.
Use the Versions Node Monitors plugin to verify that agents are running a compatible version of Java.

Running the Jenkins remoting process on an agent with Java 11 or 17 does not imply that you need to run your builds with the same version of Java.
You can continue to use any desired version of Java for individual builds.

Upvotes: 4

Sebinn Sebastian
Sebinn Sebastian

Reputation: 184

 docker exec -it <container_id> /bin/bash

If permission denied error, then,

 docker exec -u 0 -it <container_id> /bin/bash
 
 sudo apt-get update
 
 sudo apt-get install openjdk-11-jdk
 
 export PATH=$JAVA_HOME/bin:$PATH
 
 java -version

Upvotes: 0

Prodromos Antonoglou
Prodromos Antonoglou

Reputation: 11

if you have Centos you can do the following(i have done this for Centos7 and Jenkins 2.367)

sudo yum install java-11-openjdk

yum install output

if have issues with repos and you want do this manually you get the rpm's that you want and then : first update the dependency .

sudo rpm -Uvh tzdata-java-2020a-1.el7.noarch.rpm

and then

sudo rpm -Uvh java-11-openjdk-headless-11.0.8.10-1.el7.x86_64.rpm

sudo rpm -Uvh java-11-openjdk-11.0.8.10-1.el7.x86_64.rpm

then you can give

sudo update-alternatives --config java

to find the java path of java 11 --> /usr/lib/jvm/java-11-openjdk-11.0.8.10-1.el7.x86_64/bin/java

it should not be the default, if you don't want to ,you can just copy it

and use it to jenkins nodes Java path at configure nodes jenkins JavaPath

Upvotes: 1

Peter PitLock
Peter PitLock

Reputation: 1873

I opted to not install Java on the system, and followed the below approach:

  1. Go to Java 11 Downloads (registration on oracle.com required)
  2. Download the latest Java 11 Compressed Archive (zip) file. At the time of writing: jdk-11.0.15_windows-x64_bin.zip
  3. Unzip this on your build server, keep the path where you extracted to for step 5
  4. Backup Jenkins Home, especially your jenkins.xml file (same folder as jenkins.war).
  5. In Jenkins.xml, update Executable to extracted path, e.g. C:\Java\jdk-11.0.11\bin\java.exe
  6. Restart Jenkins Service

Upvotes: 2

GregOriol
GregOriol

Reputation: 136

I just upgraded a Jenkins installed from apt packages (from: http://pkg.jenkins-ci.org/debian/) with the following steps (inspired by: https://www.jenkins.io/doc/book/installing/linux/)

First, install java 11:

sudo apt install openjdk-11-jre

Then check java -version which may still show openjdk version "1.8.[x]"

If so, do choose a java-11 alternative with:

update-alternatives --config java

Then java -version should show openjdk version "11.0.[x]"

Then you can do:

systemctl restart jenkins

Upvotes: 0

Ian W
Ian W

Reputation: 4767

However you have (OpenJDK) 11 installed, as long as you have either JAVA_HOME=/path/to/jdk11 and PATH=$JAVA_HOME/bin:$PATH or explicitly run /path/to/jdk11/bin/java -jar jenkins.war or if you type java -version and it returns "11", you are fine.

Note: that is to launch jenkins. You can set the JDK available to your jenkins jobs from within Manage | Global Tools Configurationtion.

2nd Note (updated): the documentation has been updated (2021-09-16) ... The default Docker image jdk as of 2.303.1 is now 11, so you don't need to append ”-jdk11", rather users must append "-jdk8" if users want to stick to 8.

Upvotes: 1

Thomas
Thomas

Reputation: 12009

You have two options: You can globally install Java 11 on your system, for example using a package manager like apt. You would then make Java 11 your default Java.

The other option is to manually install Java, for example OpenJDK, and extract it to, for example, /opt/java and adjust the Jenkins startup script to use that specific Java installation.

Upvotes: 0

Related Questions