Hi tarun k
You're running into an issue because the JavaToolInstaller
task in your pipeline is trying to locate the JDK zip file at a Windows-specific path (D:\Java\...
), but the agent running the job is a Windows Docker container, which does not have access to that drive or path.
Could you please try the below steps:
- From your YAML code, Replace this:
jdkFile: 'D:\Java\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip'
on 54th line withjdkFile: '$(Build.SourcesDirectory)\tools\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip'
- Insert the below PowerShell script before the
JavaToolInstaller
task:- powershell: | Invoke-WebRequest -Uri "https://example.com/OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip" ` -OutFile "$(Build.SourcesDirectory)\tools\OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip" displayName: "Download Java 17 JDK Zip" condition: and(eq(variables['OSType'], 'Windows'), eq(parameters.java_version, '17'))
- Use a cloud-hosted JDK binary instead of relying on local disk, update the Windows section of your YAML like this:
- task: JavaToolInstaller@0 displayName: 'Install JDK in container agent' inputs: versionSpec: '17' jdkArchitectureOption: 'x64' jdkSourceOption: 'AzureStorage' azureResourceManagerEndpoint: '<YourServiceConnection>' azureStorageAccountName: '<StorageAccount>' azureContainerName: '<BlobContainer>' azureCommonVirtualPath: 'OpenJDK17U-jdk_x64_windows_hotspot_17.0.2_8.zip' jdkDestinationDirectory: '$(Agent.ToolsDirectory)/jdk-17' cleanDestinationDirectory: false
Alternatively, If you're using a Windows container that already has Java installed, you do not need to install the JDK manually.
Instead of JavaToolInstaller@0
, simply set the environment variable JAVA_HOME
or PATH
using the already installed JDK in the container.
- Remove or skip
JavaToolInstaller@0
- Add the below script to check Java version:
- powershell: | java -version echo "JAVA_HOME is set to: $env:JAVA_HOME" displayName: "Check existing Java in container" condition: eq(variables['OSType'], 'Windows')
Additional References:
Hope this helps!
Please Let me know if you have any queries.