@@ -35,6 +35,7 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
3535    let  compressedFileExtension : string ; 
3636    let  jdkDirectory : string ; 
3737    const  extendedJavaHome : string  =  `JAVA_HOME_${ versionSpec } ${ jdkArchitectureOption }  . toUpperCase ( ) ; 
38+     const  extendedARMJavaHome : string  =  `JAVA_HOME_${ versionSpec } ${ jdkArchitectureOption . toLowerCase ( ) }  ; 
3839
3940    toolLib . debug ( 'Trying to get tool from local cache first' ) ; 
4041    const  localVersions : string [ ]  =  toolLib . findLocalToolVersions ( 'Java' ) ; 
@@ -43,7 +44,13 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
4344    if  ( version )  {  //This version of Java JDK is already in the cache. Use it instead of downloading again. 
4445        console . log ( taskLib . loc ( 'Info_ResolvedToolFromCache' ,  version ) ) ; 
4546    }  else  if  ( preInstalled )  { 
46-         const  preInstalledJavaDirectory : string  |  undefined  =  taskLib . getVariable ( extendedJavaHome ) ; 
47+         let  preInstalledJavaDirectory : string  |  undefined  =  taskLib . getVariable ( extendedJavaHome ) ; 
48+         // MS-hosted runners set JAVA_HOME_<version>_arm64 variable for pre-installed ARM JDKs. 
49+         // If JAVA_HOME_<version>_ARM64 is not found, search for JAVA_HOME_<version>_arm64. 
50+         if  ( ! preInstalledJavaDirectory )  { 
51+             // Using process.env to read the environment variable as taskLib.getVariable converts the name to upper case. 
52+             preInstalledJavaDirectory  =  process . env [ extendedARMJavaHome ] ; 
53+         } 
4754        if  ( ! preInstalledJavaDirectory )  { 
4855            throw  new  Error ( taskLib . loc ( 'JavaNotPreinstalled' ,  versionSpec ) ) ; 
4956        } 
@@ -60,7 +67,7 @@ async function getJava(versionSpec: string, jdkArchitectureOption: string): Prom
6067            const  fileNameAndPath : string  =  taskLib . getInput ( 'azureCommonVirtualFile' ,  true ) ; 
6168            const  azureDownloader  =  new  AzureStorageArtifactDownloader ( 
6269                taskLib . getInput ( 'azureResourceManagerEndpoint' ,  true ) , 
63-                 taskLib . getInput ( 'azureStorageAccountName' ,  true ) ,   
70+                 taskLib . getInput ( 'azureStorageAccountName' ,  true ) , 
6471                taskLib . getInput ( 'azureContainerName' ,  true ) , 
6572                "" , 
6673                taskLib . getInput ( 'azureResourceGroupName' ,  false ) , 
0 commit comments