diff --git a/Jenkinsfile b/Jenkinsfile index 1e731da27..f82132330 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,8 +6,9 @@ buildPlugin( useContainerAgent: false, // Show failures on all configurations failFast: false, - // Test Java 11 with minimum Jenkins version, Java 17 with a more recent version + // Test Java 11, 17, and 21 configurations: [ [platform: 'linux', jdk: 17], + [platform: 'linux', jdk: '21', jenkins: '2.401.3'], [platform: 'windows', jdk: 11], ]) diff --git a/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java b/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java index d8e81950c..de51bea9a 100644 --- a/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java +++ b/src/test/java/io/jenkins/docker/connector/DockerComputerAttachConnectorTest.java @@ -21,9 +21,9 @@ public void connectAgentViaDirectAttach() throws Exception { @Test public void connectAgentViaDirectAttachWithCustomCmd() throws Exception { final DockerComputerAttachConnector connector = new DockerComputerAttachConnector(COMMON_IMAGE_USERNAME); - // We could setJavaExe("/usr/local/openjdk-8/bin/java") too, but that'd mean - // we'd break the instant that the public docker image's JVM updates to 9 or - // higher; best stick to just using the $PATH. + // We could setJavaExe("/opt/jdk-11/bin/java") too, but that'd + // mean we'd break the instant that the public docker image's JVM + // updates to a newer JDK; best stick to just using the $PATH. connector.setJvmArgsString("-Xmx1g" + "\n" + "-Dfoo=bar\n"); connector.setEntryPointCmdString("java\n" + "${" + ArgumentVariables.JvmArgs.getName() + "}\n" diff --git a/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java b/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java index 355488dbd..3ed96e415 100644 --- a/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java +++ b/src/test/java/io/jenkins/docker/connector/DockerComputerConnectorTest.java @@ -48,19 +48,12 @@ private static int getJavaVersion() { final String systemPropertyName = "java.version"; final String javaVersion = System.getProperty(systemPropertyName); try { - if (javaVersion.startsWith("1.")) { - // we're using Java 8 or lower so the syntax is 1.x where x is the version we - // want. - // ... and we know that x will be a single digit. - // e.g. 1.8.1 is Java 8, 1.6.3 is Java 6 etc. - final String secondNumber = javaVersion.substring(2, 3); - return Integer.parseInt(secondNumber); - } - // otherwise we're using Java 9 or higher so the syntax is x.n... + // We're using Java 9 or higher so the syntax is x.n... // ... but x might be multiple digits. // e.g. 9.0 is Java 9, 11.123.4 is Java 11 etc. + // Early access builds report as "21-ea". Remove all text after "-". final int indexOfPeriod = javaVersion.indexOf('.'); - final String firstNumber = indexOfPeriod < 0 ? javaVersion : javaVersion.substring(0, indexOfPeriod); + final String firstNumber = javaVersion.replaceAll("[-.].*", ""); return Integer.parseInt(firstNumber); } catch (RuntimeException ex) { throw new IllegalStateException(