Skip to content

Commit

Permalink
Clean up JI_JAVA_TOOL env var setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpobst committed Jan 14, 2025
1 parent f792b4e commit 9febc43
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
26 changes: 26 additions & 0 deletions build-tools/automation/yaml-templates/setup-java-environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Sets JI_JAVA_HOME to the requested Java SDK version

parameters:
jdkDirectory: # Explicit SDK path to use, will take precedence if specified
jdkVersion: 17 # SDK version to use, valid values are 11/17/21

steps:
# Use the explicit provided jdkDirectory
- pwsh: |
Write-Host "##vso[task.setvariable variable=JI_JAVA_HOME]${{ parameters.jdkDirectory }}"
displayName: Set JI_JAVA_HOME to ${{ parameters.jdkDirectory }}
condition: and(succeeded(), ne('${{ parameters.jdkDirectory }}', ''))

# If an explicit Java SDK path wasn't provided, use jdkVersion
- pwsh: |
$arch = "variables['agent.osarchitecture']" -eq "ARM64" ? "arm64" : "X64"
$env_var = "JAVA_HOME_${{ parameters.jdkVersion }}_" + $arch
$env_value = [Environment]::GetEnvironmentVariable($env_var)
Write-Host "Setting JI_JAVA_HOME to environment variable: '$env_var' ($env_value)"
Write-Host "##vso[task.setvariable variable=JI_JAVA_HOME]$env_value"
displayName: set JI_JAVA_HOME to version ${{ parameters.jdkVersion }}
condition: and(succeeded(), eq('${{ parameters.jdkDirectory }}', ''))

- script: |
echo $(JI_JAVA_HOME)
displayName: print JI_JAVA_HOME
19 changes: 5 additions & 14 deletions build-tools/automation/yaml-templates/setup-test-environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,11 @@ steps:
jdkMajorVersion: ${{ parameters.jdkMajorVersion }}
useAgentJdkPath: ${{ parameters.useAgentJdkPath }}

# If an explicit Java SDK path wasn't provided, choose JDK-17 for the appropriate architecture
- pwsh: |
Write-Host "##vso[task.setvariable variable=JI_JAVA_HOME]$env:JAVA_HOME_17_X64"
displayName: set JI_JAVA_HOME to JAVA_HOME_17_X64
condition: and(succeeded(), eq('${{ parameters.jdkTestFolder }}', ''), eq(variables['agent.osarchitecture'], 'X64'))

- pwsh: |
Write-Host "##vso[task.setvariable variable=JI_JAVA_HOME]$env:JAVA_HOME_17_arm64"
displayName: set JI_JAVA_HOME to JAVA_HOME_17_arm64
condition: and(succeeded(), eq('${{ parameters.jdkTestFolder }}', ''), eq(variables['agent.osarchitecture'], 'ARM64'))

- script: |
echo $(JI_JAVA_HOME)
displayName: print JI_JAVA_HOME
# Set JI_JAVA_HOME to requested JDK
- template: /build-tools/automation/yaml-templates/setup-java-environment.yaml
parameters:
jdkDirectory: ${{ parameters.jdkTestFolder }}
jdkVersion: ${{ parameters.jdkVersion }}

# Install latest .NET
- template: /build-tools/automation/yaml-templates/use-dot-net.yaml
Expand Down

0 comments on commit 9febc43

Please sign in to comment.