From 3035318d291b28a71766e0cf6775927fe4b8a5f1 Mon Sep 17 00:00:00 2001 From: ray chen Date: Thu, 4 Sep 2025 19:01:02 +0000 Subject: [PATCH 1/4] Added separte step to install java8 --- eng/pipelines/templates/jobs/live.tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/eng/pipelines/templates/jobs/live.tests.yml b/eng/pipelines/templates/jobs/live.tests.yml index a8dff6042e19..86f2c32065bc 100644 --- a/eng/pipelines/templates/jobs/live.tests.yml +++ b/eng/pipelines/templates/jobs/live.tests.yml @@ -85,6 +85,9 @@ jobs: - ${{ if and(eq(parameters.UseHttpFaultInjector, 'true'), not(contains(variables['OSVmImage'], 'mac'))) }}: - template: /eng/pipelines/templates/steps/http-fault-injector.yml + # Install Java 8 on macOS 15+ since they're not included by default. + - template: /eng/pipelines/templates/steps/install-java8-macos.yml + # If the Java test versions isn't one of the LTS versions, or in other words is the latest Java version we're # testing against and that isn't an LTS version at the time (ex. latest LTS is Java 21 but we're testing against # Java 24), then install the latest Java version and use that to run tests. From f1e551e24d7bf658f2b89a3f1d923fdad0683964 Mon Sep 17 00:00:00 2001 From: ray chen Date: Thu, 4 Sep 2025 22:03:00 +0000 Subject: [PATCH 2/4] Install java 8 in the install-latest-jdk template and set java_home --- eng/pipelines/templates/jobs/ci.tests.yml | 2 -- eng/pipelines/templates/jobs/live.tests.yml | 3 --- .../templates/steps/install-latest-jdk.yml | 15 +++++++++++ eng/scripts/Install-Latest-JDK.ps1 | 27 ++++++++++++++++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/eng/pipelines/templates/jobs/ci.tests.yml b/eng/pipelines/templates/jobs/ci.tests.yml index 6ec9de92541d..fdf148f93e98 100644 --- a/eng/pipelines/templates/jobs/ci.tests.yml +++ b/eng/pipelines/templates/jobs/ci.tests.yml @@ -110,8 +110,6 @@ jobs: ServiceDirectory: ${{parameters.ServiceDirectory}} ExcludePaths: ${{parameters.ExcludePaths}} - - template: /eng/pipelines/templates/steps/install-java8-macos.yml - - template: /eng/common/testproxy/test-proxy-tool.yml parameters: runProxy: true diff --git a/eng/pipelines/templates/jobs/live.tests.yml b/eng/pipelines/templates/jobs/live.tests.yml index 86f2c32065bc..a8dff6042e19 100644 --- a/eng/pipelines/templates/jobs/live.tests.yml +++ b/eng/pipelines/templates/jobs/live.tests.yml @@ -85,9 +85,6 @@ jobs: - ${{ if and(eq(parameters.UseHttpFaultInjector, 'true'), not(contains(variables['OSVmImage'], 'mac'))) }}: - template: /eng/pipelines/templates/steps/http-fault-injector.yml - # Install Java 8 on macOS 15+ since they're not included by default. - - template: /eng/pipelines/templates/steps/install-java8-macos.yml - # If the Java test versions isn't one of the LTS versions, or in other words is the latest Java version we're # testing against and that isn't an LTS version at the time (ex. latest LTS is Java 21 but we're testing against # Java 24), then install the latest Java version and use that to run tests. diff --git a/eng/pipelines/templates/steps/install-latest-jdk.yml b/eng/pipelines/templates/steps/install-latest-jdk.yml index 8149c86e16d1..a7c6a20a8d31 100644 --- a/eng/pipelines/templates/steps/install-latest-jdk.yml +++ b/eng/pipelines/templates/steps/install-latest-jdk.yml @@ -31,3 +31,18 @@ steps: Write-Host "Latest JDK: $Env:JAVA_HOME_${{ parameters.LatestJdkFeatureVersion }}_X64" displayName: 'Verify Latest JDK Install' condition: eq(variables['IsLatestNonLtsJdk'], 'true') + + - task: PowerShell@2 + displayName: 'Install JDK 8 on macOS' + inputs: + pwsh: true + arguments: > + -JdkFeatureVersion 8 + workingDirectory: $(Agent.BuildDirectory) + filePath: eng/scripts/Install-Latest-JDK.ps1 + condition: eq(variables['Agent.OS'], 'Darwin') + + - pwsh: | + Write-Host "Java 8 JDK: $Env:JAVA_HOME_8_X64" + displayName: 'Verify JDK 8 Install' + condition: eq(variables['Agent.OS'], 'Darwin') diff --git a/eng/scripts/Install-Latest-JDK.ps1 b/eng/scripts/Install-Latest-JDK.ps1 index c5ae818508b8..bca1d3eb9ddf 100644 --- a/eng/scripts/Install-Latest-JDK.ps1 +++ b/eng/scripts/Install-Latest-JDK.ps1 @@ -16,6 +16,15 @@ if ($IsWindows) { $os = "linux" } +$jdkFeatureVersionJavaHome = "JAVA_HOME_" + $JdkFeatureVersion + "_X64" +Write-Host "Checking if $jdkFeatureVersionJavaHome is already set and exist..." +$javaHomeValue = [System.Environment]::GetEnvironmentVariable($jdkFeatureVersionJavaHome) +$jdkBinPath = Join-Path -Path $javaHomeValue -ChildPath "bin/java" +if (Test-Path -Path $jdkBinPath) { + Write-Host "$jdkFeatureVersionJavaHome is already set to $javaHomeValue" + exit 0 +} + $getInstalls = "$adoptiumApiUrl/v3/assets/latest/$JdkFeatureVersion/hotspot?architecture=x64&image_type=jdk&os=$os&vendor=eclipse" $jdkUnzipName = "jdk-$JdkFeatureVersion" @@ -43,11 +52,21 @@ if (!(Test-Path -Path $jdkUnzipName -PathType container)) { } $javaHome = (Convert-Path $jdkUnzipName) -Write-Host "Latest JDK: $javaHome" +if ($IsMacOS) { + # On macOS, the JDK is inside a subdirectory of the unzipped folder. + $correctJavaHome = Join-Path -Path $javaHome -ChildPath "Contents/Home" + $javaBinPath = Join-Path -Path $correctJavaHome -ChildPath "bin/java" + if (Test-Path $javaBinPath) { + $javaHome = $correctJavaHome + Write-Host "Updated JAVA_HOME on macOS: $correctJavaHome" + } else { + Write-Error "Failed to find Java at: $correctJavaHome" + } +} + +Write-Host "Latest JDK: $javaHome" Write-Host "Current JAVA_HOME: $Env:JAVA_HOME" Write-Host "##vso[task.setvariable variable=JAVA_HOME;]$javaHome" -Write-Host "Updated JAVA_HOME: $Env:JAVA_HOME" - -$jdkFeatureVersionJavaHome = "JAVA_HOME_" + $JdkFeatureVersion + "_X64" +Write-Host "Updated JAVA_HOME to : $javaHome" Write-Host "##vso[task.setvariable variable=$jdkFeatureVersionJavaHome;]$javaHome" From f16d0ed41342e9a2c013e5056a992d70a8bbc4d3 Mon Sep 17 00:00:00 2001 From: ray chen Date: Thu, 4 Sep 2025 22:14:08 +0000 Subject: [PATCH 3/4] Check null for the Java_Home --- eng/scripts/Install-Latest-JDK.ps1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/eng/scripts/Install-Latest-JDK.ps1 b/eng/scripts/Install-Latest-JDK.ps1 index bca1d3eb9ddf..8012864db48d 100644 --- a/eng/scripts/Install-Latest-JDK.ps1 +++ b/eng/scripts/Install-Latest-JDK.ps1 @@ -19,10 +19,14 @@ if ($IsWindows) { $jdkFeatureVersionJavaHome = "JAVA_HOME_" + $JdkFeatureVersion + "_X64" Write-Host "Checking if $jdkFeatureVersionJavaHome is already set and exist..." $javaHomeValue = [System.Environment]::GetEnvironmentVariable($jdkFeatureVersionJavaHome) -$jdkBinPath = Join-Path -Path $javaHomeValue -ChildPath "bin/java" -if (Test-Path -Path $jdkBinPath) { - Write-Host "$jdkFeatureVersionJavaHome is already set to $javaHomeValue" - exit 0 +if ($javaHomeValue) { + $jdkBinPath = Join-Path -Path $javaHomeValue -ChildPath "bin/java" + if (Test-Path -Path $jdkBinPath) { + Write-Host "$jdkFeatureVersionJavaHome is already set to $javaHomeValue" + exit 0 + } +} else { + Write-Host "$jdkFeatureVersionJavaHome is not set, proceeding with installation..." } $getInstalls = "$adoptiumApiUrl/v3/assets/latest/$JdkFeatureVersion/hotspot?architecture=x64&image_type=jdk&os=$os&vendor=eclipse" From 1f9a2944aa2c6ea9b85acb3e55f72899170e6e8f Mon Sep 17 00:00:00 2001 From: ray chen Date: Thu, 4 Sep 2025 22:52:55 +0000 Subject: [PATCH 4/4] Cleaned up code --- .../templates/steps/install-java8-macos.yml | 43 ------------------- .../templates/steps/install-latest-jdk.yml | 5 --- eng/scripts/Install-Latest-JDK.ps1 | 3 +- 3 files changed, 2 insertions(+), 49 deletions(-) delete mode 100644 eng/pipelines/templates/steps/install-java8-macos.yml diff --git a/eng/pipelines/templates/steps/install-java8-macos.yml b/eng/pipelines/templates/steps/install-java8-macos.yml deleted file mode 100644 index f4ed42f82d26..000000000000 --- a/eng/pipelines/templates/steps/install-java8-macos.yml +++ /dev/null @@ -1,43 +0,0 @@ -steps: - - task: PowerShell@2 - displayName: 'Install Java 8 JDK on macOS 15' - inputs: - pwsh: true - targetType: 'inline' - script: | - # Check macOS version - $osVersion = sw_vers -productVersion 2>$null - Write-Host "Current macOS version: $osVersion" - - if ($osVersion -match '^(\d+)\.') { - $majorVersion = [int]$matches[1] - Write-Host "Detected macOS major version: $majorVersion" - - if ($majorVersion -ge 15) { - Write-Host "macOS $majorVersion detected (15 or higher). Proceeding with Java 8 installation." - Write-Host "##vso[task.setvariable variable=MacOS_Latest]true" - - # Call the existing installation script - & "$(Build.SourcesDirectory)/eng/scripts/Install-Latest-JDK.ps1" -JdkFeatureVersion 8 - } else { - Write-Host "macOS version is $osVersion (major version $majorVersion), which is lower than 15. Skipping Java 8 installation." - } - } else { - Write-Error "Failed parse macOS version '$osVersion'." - } - - workingDirectory: $(Agent.BuildDirectory) - condition: and(eq(variables['JavaTestVersion'], '1.8'), eq(variables['Agent.OS'], 'Darwin')) - - - pwsh: | - Write-Host "JAVA_HOME_8_X64: $Env:JAVA_HOME_8_X64" - $macOsJavaHome = Join-Path $Env:JAVA_HOME_8_X64 "Contents/Home" - - if (Test-Path $macOsJavaHome) { - Write-Host "##vso[task.setvariable variable=JAVA_HOME_8_X64]$macOsJavaHome" - Write-Host "Updated JAVA_HOME_8_X64 to: $macOsJavaHome" - } else { - Write-Host "Failed to find Java 8 at: $macOsJavaHome" - } - displayName: 'Verify Java 8 Install' - condition: and(eq(variables['JavaTestVersion'], '1.8'), eq(variables['Agent.OS'], 'Darwin'), eq(variables['MacOS_Latest'], 'true')) diff --git a/eng/pipelines/templates/steps/install-latest-jdk.yml b/eng/pipelines/templates/steps/install-latest-jdk.yml index a7c6a20a8d31..3c7273d81938 100644 --- a/eng/pipelines/templates/steps/install-latest-jdk.yml +++ b/eng/pipelines/templates/steps/install-latest-jdk.yml @@ -41,8 +41,3 @@ steps: workingDirectory: $(Agent.BuildDirectory) filePath: eng/scripts/Install-Latest-JDK.ps1 condition: eq(variables['Agent.OS'], 'Darwin') - - - pwsh: | - Write-Host "Java 8 JDK: $Env:JAVA_HOME_8_X64" - displayName: 'Verify JDK 8 Install' - condition: eq(variables['Agent.OS'], 'Darwin') diff --git a/eng/scripts/Install-Latest-JDK.ps1 b/eng/scripts/Install-Latest-JDK.ps1 index 8012864db48d..4a6c472a7285 100644 --- a/eng/scripts/Install-Latest-JDK.ps1 +++ b/eng/scripts/Install-Latest-JDK.ps1 @@ -17,7 +17,7 @@ if ($IsWindows) { } $jdkFeatureVersionJavaHome = "JAVA_HOME_" + $JdkFeatureVersion + "_X64" -Write-Host "Checking if $jdkFeatureVersionJavaHome is already set and exist..." +Write-Host "Checking if $jdkFeatureVersionJavaHome is already set and exists..." $javaHomeValue = [System.Environment]::GetEnvironmentVariable($jdkFeatureVersionJavaHome) if ($javaHomeValue) { $jdkBinPath = Join-Path -Path $javaHomeValue -ChildPath "bin/java" @@ -66,6 +66,7 @@ if ($IsMacOS) { Write-Host "Updated JAVA_HOME on macOS: $correctJavaHome" } else { Write-Error "Failed to find Java at: $correctJavaHome" + exit 1 } }