Jenkins setup: I have my Jenkins controller setup on ECS cluster and also using ECS plugin to provision Jenkins docker agents on ECS.
For Jenkins agents, i am using jenkins/inbound-agent:latest-alpine-jdk21 docker image and the ECS plugin uses JNLP for connection b/w controller and the agent. I able to successfully run jobs on docker containers on ECS.
The issue i am facing is with the Java version, some of my jobs needs Java 1.8 version but the jenkins agent needed Java 21. I even created my own custom agent docker image with Java 8 installed and added in PATH and Java 21 removed from PATH and made agent to use Java 21 binary via JENKINS_JAVA_BIN. But still the jobs always uses Java 21, i even verified with which java and echo $PATH commands and both of them shows java 1.8 only but still java -version and mvn -version always prints Java 21.
I want to know is it even possible to change the Java version when using JNLP for the agents, i think since agent connects through JNLP which creates a Java process with Java 21, so that’s why i not able to use Java 1.8 even its in the PATH and default Java.
Below is the output of my diagnosis from job output:
+ which java
/usr/lib/jvm/java-1.8-openjdk/bin/java
+ echo /usr/lib/jvm/java-1.8-openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/maven/bin:/opt/ant/bin:/opt/gradle/bin
/usr/lib/jvm/java-1.8-openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/maven/bin:/opt/ant/bin:/opt/gradle/bin
+ echo /usr/lib/jvm/java-1.8-openjdk
/usr/lib/jvm/java-1.8-openjdk
+ java -version
openjdk version "21.0.8" 2025-07-15 LTS
OpenJDK Runtime Environment Temurin-21.0.8+9 (build 21.0.8+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.8+9 (build 21.0.8+9-LTS, mixed mode)
+ mvn -version
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /opt/maven
Java version: 21.0.8, vendor: Eclipse Adoptium, runtime: /opt/java/jdk21
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "6.1.156-177.286.amzn2023.x86_64", arch: "amd64", family: "unix"
+ echo /home/jenkins
/home/jenkins
+ type java
java is /usr/lib/jvm/java-1.8-openjdk/bin/java