> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://support.stacktrack.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Java Build Management for Jenkins Runners

### Jenkins Build Service and Refinery Runners for Jenkins: Improved Java Version Support

![](https://storage.crisp.chat/users/helpdesk/website/-/5/2/b/7/52b79f719eb25800/jenkins-java-support_1e0fv9f.png =767xauto)


Services:  
1. [StackTrack Refinery Runners for Jenkins](/products/managed-jenkins-build-service/)
2. [Jenkins Build Service](/products/managed-jenkins-build-service/)

We are updating the build agents to improve how Java versions are managed across Jenkins controllers, agents, jobs, and pipelines.

This change gives teams more flexibility when selecting Java versions for build workloads, while helping us prepare the platform for future Jenkins and Java upgrades while lowering operational risk.
## What is changing
Java version selection can be controlled at multiple levels:
* Controller level
* Folder level
* Job or pipeline level

We are also decoupling the Java runtime used by Jenkins agents from the Java version used inside build steps, including:
* Pipeline `sh` commands
* Freestyle job shell steps
* Jobs that need a specific JDK version for compilation, testing, or tooling

This means Jenkins agents can run on the Java version required by the Jenkins platform, while individual jobs and pipelines can still use the Java version required by the application being built.

|| Previous iterations of our platform had some separation for the Java versions but we also allowed / enabled you to also use the system Java installation and because of that we created a dependency between your builds and the system Java that impacted our ability to perform upgrades. This change fixes that behaviour.
## Why this matters
This update helps teams:
* Adopt newer Java versions in a controlled way
* Continue supporting workloads that require older Java versions
* Reduce risk during future Jenkins and JDK upgrades
* Avoid coupling Jenkins platform upgrades to every application build requirement
* Give individual teams more control over the Java version used by their jobs and pipelines
## Impact
This is a **non-disruptive change**.
There is no expected downtime and no expected impact to running jobs or pipelines.
Existing configurations will continue to work as they do today unless a Java version is explicitly overridden.
For managed Jenkins agents, StackTrack will ensure the Jenkins agent runtime uses a supported Java version for the Jenkins platform. For Jenkins LTS `2.555.1` and later, Jenkins requires Java 21 or Java 25 on both the controller JVM and agent JVMs. ([Jenkins](https://www.jenkins.io/doc/upgrade-guide/2.555/?utm_source=chatgpt.com))
## Selecting a Java version in jobs and pipelines
Once this change is enabled, customers can select the Java version used by their jobs or pipelines by setting the `JENV_VERSION` environment variable.
| Java Version | `JENV_VERSION` value | `JAVA_HOME` |
| ---- |
| Java 6 | `1.6` | `/usr/lib/jvm/jdk-1.6` |
| Java 7 | `1.7` | `/usr/lib/jvm/jdk-1.7` |
| Java 8 | `1.8` | `/usr/lib/jvm/jdk-1.8` |
| Java 11 | `11` | `/usr/lib/jvm/jdk-11` |
| Java 17 | `17` | `/usr/lib/jvm/jdk-17` |
| Java 21 — default | `21` | `/usr/lib/jvm/jdk-21` |
| Java 25 | `25` | `/usr/lib/jvm/jdk-25` |
Example:
```
pipeline {
  agent any

  environment {
    JENV_VERSION = '17'
  }

  stages {
    stage('Check Java version') {
      steps {
        sh 'java -version'
      }
    }
  }
}
```
## Using Jenkins JDK tools
Customers can also use Jenkins JDK tools instead of setting `JENV_VERSION` directly.
| JDK Tool Name | `JAVA_HOME` | Declarative Pipeline | Scripted Pipeline |
| ---- |
| `JDK1.6` | `/usr/lib/jvm/jdk-1.6` | `tools { jdk 'JDK1.6' }` | `def javaHome = tool 'JDK1.6'env.JAVA_HOME = javaHome` |
| `JDK1.7` | `/usr/lib/jvm/jdk-1.7` | `tools { jdk 'JDK1.7' }` | `def javaHome = tool 'JDK1.7'env.JAVA_HOME = javaHome` |
| `JDK1.8` | `/usr/lib/jvm/jdk-1.8` | `tools { jdk 'JDK1.8' }` | `def javaHome = tool 'JDK1.8'env.JAVA_HOME = javaHome` |
| `JDK11` | `/usr/lib/jvm/jdk-11` | `tools { jdk 'JDK11' }` | `def javaHome = tool 'JDK11'env.JAVA_HOME = javaHome` |
| `JDK17` | `/usr/lib/jvm/jdk-17` | `tools { jdk 'JDK17' }` | `def javaHome = tool 'JDK17'env.JAVA_HOME = javaHome` |
| `JDK21` | `/usr/lib/jvm/jdk-21` | `tools { jdk 'JDK21' }` | `def javaHome = tool 'JDK21'env.JAVA_HOME = javaHome` |
| `JDK25` | `/usr/lib/jvm/jdk-25` | `tools { jdk 'JDK25' }` | `def javaHome = tool 'JDK25'env.JAVA_HOME = javaHome` |
Example declarative pipeline:
```
pipeline {
  agent any

  tools {
    jdk 'JDK21'
  }

  stages {
    stage('Check Java version') {
      steps {
        sh 'java -version'
      }
    }
  }
}
```
Example scripted pipeline:
```
node {
  def javaHome = tool 'JDK21'
  env.JAVA_HOME = javaHome
  env.PATH = "${javaHome}/bin:${env.PATH}"

  sh 'java -version'
}
```

## Customers with permanent agents
Customers who own or manage their own permanent Jenkins agents must ensure those agents are upgraded to Java 21 or Java 25 before moving to Jenkins LTS `2.555.1` or later.
From Jenkins LTS `2.555.1`, Java 21 or Java 25 is required for both the Jenkins controller and agent JVMs. Java 17 is not supported for Jenkins `2.555.1` and later. ([Jenkins](https://www.jenkins.io/doc/upgrade-guide/2.555/?utm_source=chatgpt.com))
This does not prevent jobs from using older Java versions for build steps where required. 

The Jenkins agent runtime and the Java version used inside a job or pipeline can now be managed separately.


# Customers with Kubernetes based agents

With a pipeline like this you can easily support running different JDKs.

```
pipeline {
	agent {
		kubernetes {
                   yaml """
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: jdk8
    image: eclipse-temurin:8-jdk-jammy
    command: ['cat']
    tty: true
  - name: jdk11
    image: eclipse-temurin:11-jdk-jammy
    command: ['cat']
    tty: true
  - name: jdk17
    image: eclipse-temurin:17-jdk-jammy
    command: ['cat']
    tty: true
  - name: jdk21
    image: eclipse-temurin:21-jdk-jammy
    command: ['cat']
    tty: true
  - name: jdk25
    image: eclipse-temurin:25-jdk-jammy
    command: ['cat']
    tty: true
  - name: kubectl
    image: domain.jfrog.io/devops-docker-prod/dtzar/helm-kubectl:3.3.4
    command: ['cat']
    tty: true
  - name: octo
    image: octopusdeploy/octo
    command: ['cat']
    tty: true
  imagePullSecrets:
  - name: saas-artifactory
"""
		}
	}

	options {
		timeout(time: 30, unit: 'MINUTES')
	}

	stages {
		stage('JDK 8') {
			steps {
				container('jdk8') {
					sh 'java -version && echo JAVA_HOME=$JAVA_HOME'
				}
			}
		}

		stage('JDK 11') {
			steps {
				container('jdk11') {
					sh 'java -version && echo JAVA_HOME=$JAVA_HOME'
				}
			}
		}

		stage('JDK 17') {
			steps {
				container('jdk17') {
					sh 'java -version && echo JAVA_HOME=$JAVA_HOME'
				}
			}
		}

		stage('JDK 21') {
			steps {
				container('jdk21') {
					sh 'java -version && echo JAVA_HOME=$JAVA_HOME'
				}
			}
		}

		stage('JDK 25') {
			steps {
				container('jdk25') {
					sh 'java -version && echo JAVA_HOME=$JAVA_HOME'
				}
			}
		}

		stage('Tools Test') {
			steps {
				container('kubectl') {
					sh 'kubectl version --client=true --short || true'
				}
				container('octo') {
					sh 'octo version || true'
				}
			}
		}
	}
}
```