Migrate to Java 21

5 minute read

Java 21 was released on September 19, 2023, as a long-term support (LTS) version. The Jenkins community supports running Jenkins with Java 21 since version 2.426.1 and CloudBees CI supports running in Java 21 since version 2.479.3.1.

CloudBees has validated the core functionality and all plugins in the CloudBees Assurance Program (CAP) work correctly when using Java 21. Plugins that are not part of the CAP may work, but they have not been verified and may cause issues especially in mixed JVM scenarios.

If you manage your CloudBees CI on modern cloud platforms using Helm charts, both the operations center and controllers are automatically upgraded to Java 21, the same applies to agent images. If you are not using the CloudBees CI agent image, you need to manually update your agent image to include and use Java 21 as the default Java installation. Similarly, shared agents and cloud agents must be manually updated to use Java 21.

Supported configurations

CloudBees performs full test flows with the following supported JDKs or JREs:

  • OpenJDK JDK/JRE 17 - 64 bits

  • OpenJDK JDK/JRE 21 - 64 bits

CloudBees CI versions 2.479.3.1 - 2.541.3.36069

Table 1. CloudBees CI versions 2.479.3.1 - 2.541.3.36069
Component Supported Java version

Operations center

Java 21 and Java 17

Controller and agents

Java 21 (only if the operations center is also running Java 21) and Java 17

Operations center shared agents

Java 21 (only if the operations center is also running Java 21) and Java 17

CloudBees CI version 2.555.1.36485 or later

Table 2. CloudBees CI 2.555.1.36485 or later
Component Supported Java version

Operations center

Java 21

Controller and agents

Java 21

Operations center shared agents

Java 21

Action required

CloudBees supports mixed-mode JVM usage in CloudBees CI versions 2.479.3.1 - 2.541.3.36069. Starting with CloudBees CI version 2.555.1.36485 or later, Java 21 is required for all components and mixed-mode JVM usage is no longer supported.

Before upgrading to CloudBees CI version 2.555.1.36485 or later, you must complete the following steps:

Upgrade the JVM used to run CloudBees CI

Upgrade the JVM on all components to Java 21 while remaining on CloudBees CI versions 2.479.3.1 - 2.541.3.36069. CloudBees recommends the following upgrade sequence. If this is not possible due to specific installation constraints, you can first upgrade the controllers and then upgrade the agents.

  1. Upgrade all agents (permanent and cloud agents) to Java 21. If you use custom build agents, update those podTemplates to Java 21.

    Upgrading to Java 21 only affects the runtime processes. Build jobs can continue to use different JDK versions (for example, 8, 11, 17, or 26) via container (for example, Docker) or VM definitions, tool locations, or environment variables in the build configuration (for example, a Jenkinsfile).
  2. Upgrade all controllers to Java 21. If you use Helm charts, controllers are automatically upgraded to Java 21. If you have customized your deployment images, update them to use the -jdk21 image tag.

  3. Upgrade the operations center to Java 21. If you use Helm charts, the operations center is automatically upgraded to Java 21. If you have customized your deployment images, update them to use the -jdk21 image tag.

All components must be running Java 21 before proceeding to Upgrade the CloudBees CI software.

Upgrade the CloudBees CI software

After verifying all components are healthy and running Java 21, upgrade the CloudBees CI software to 2.555.1.36485 or later.

  • As with any upgrade, CloudBees recommends that you back up $JENKINS_HOME and test the upgrade with a backup before you perform the upgrade on your production instance.

  • Controllers may remain on older software versions in accordance with the CloudBees maintenance lifecycle policies and can be upgraded at a later time.

  1. Upgrade CloudBees CI.

  2. Upgrade the plugins to support Java 21 and ensure compatibility with the most recent CloudBees CI releases.

    CloudBees has verified that all plugins in the CAP run without issue when using Java 21. If you discover a previously unreported issue, contact CloudBees Support. If the issue involves a Jenkins community plugin, CloudBees will report it and can suggest workarounds to avoid a broken plugin.

  3. Back up $JENKINS_HOME again after upgrading CloudBees CI and any required plugins.

Monitor the Java versions automatically

CloudBees CI on modern cloud platforms controllers and build agents verify Java requirements and notify users when they are launched using an unsupported version. The Versions Node Monitors plugin also provides detailed Java version monitoring.

JVM version on container images

CloudBees provides the following naming structure for container images:

  • an image with the -jdk21 suffix indicates Java 21

  • an image without a suffix is the same as using the -jdk21 suffix

Known issues

Refer to the following sections for any known issues that may affect your migration to Java 21.

JVM version on agents

All agents must run Java 21. You can validate each agent’s version using the Version Node Monitors plugin. This plugin provides information about the JVM version of each agent on the node management screen of your CloudBees CI instance. You can also configure this plugin to automatically disconnect any agent with an incorrect JVM version.

JVM version on operations center shared agents

JVM instances are used to establish the remoting connection between shared agents and controllers, as well as shared agents and the operations center. Additional JVMs could be installed on the agent computer and used as build tools by controller jobs. Those JVMs are irrelevant in this context, and there is no need to update them as part of the CloudBees CI Java 21 migration.

Depending on the launch method and agent configuration, you may have to take additional actions when you upgrade to Java 21.

"Launch agent by connecting it to the controller" launch method

This launch method is also known as an "inbound" agent. It is the agent that initiates the connection to the controller. This configuration also requires the agent computer to initiate the connection to the operations center. This launch method requires two JVM instances. One maintains the connection to the operations center and it is called the shared agent control JVM. The other connects to the controller when the agent is leased, and it is called the agent JVM. Both JVM instances must run Java 21.

"Launch build agents via SSH" launch method

This launch method is also known as an "outbound" agent. It means the controller is initiating the connection to the agent computer via SSH and then automatically starting the agent JVM.

There is no shared agent control JVM involved in this configuration. There is only one JVM, the agent JVM, which must run Java 21. The path to this JVM binary is configurable in the shared agent configurations.

Execute jobs on CloudBees CI

CloudBees CI jobs can be executed on Java versions that differ from the controller/agent runtime Java version. Generally, CloudBees CI allows any version of JRE/JDK to be invoked during the build. That includes executing Java commands from the CLI, as well as installing and executing build steps using a JDK managed by JDK tool installers.