Search code examples
azureazure-pipelinesazure-pipelines-build-taskazure-pipelines-yamlazure-pipelines-tasks

Installing Java 14 on Azure pipeline for MacOS agent


I need to use Java 14 on a hosted agent (macos-12) and I'm trying to install it through a script and then use the JavaToolInstaller task to make it available.

I have modified the script from https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/tool/java-tool-installer?view=azure-devops

jobs:
- job: RunApiTests
  pool:
    vmImage: macOS-12
  condition: ne(variables['Build.SourceBranch'], 'refs/heads/main')
  steps:
  - task: JavaToolInstaller@0
    displayName: Install Java 14
    inputs:
      versionSpec: '14'
      jdkArchitectureOption: 'x64'
      jdkSourceOption: AzureStorage
      azureResourceManagerEndpoint: {azureResourceManagerEndpoint}
      azureStorageAccountName: {azureStorageAccountName}
      azureContainerName: openjdk
      azureCommonVirtualFile: 'openjdk-14.0.2.zip'
      jdkDestinationDirectory: '$(agent.toolsDirectory)/jdk14'
      cleanDestinationDirectory: false

Below is the error I am getting:

##[error]JDK file is not valid. Verify if JDK file contains only one root folder with 'bin' inside.

I downloaded the 14.0.2 (build 14.0.2+12) jdk for Mac from https://jdk.java.net/archive/ and I compressed only the Home folder to a zip file because bin is in there.

So, as per the requirement, the zip file contains only one root folder 'Home' with bin inside.

I need help on why I'm getting this error.


Solution

  • I tried to test your yaml in my pipeline and it works. The following are my steps.

    I downloaded this package:

    enter image description here

    In my zip, I have these files:

    enter image description here

    Uploaded to the storage account.

    enter image description here

    Yaml:

    trigger:
    - none
    
    pool:
      vmImage: macos-12
    
    steps:
    - task: JavaToolInstaller@0
      inputs:
        versionSpec: '14'
        jdkArchitectureOption: 'x64'
        jdkSourceOption: 'AzureStorage'
        azureResourceManagerEndpoint: 'myEndpoint'
        azureStorageAccountName: 'teststorage'
        azureContainerName: 'test'
        azureCommonVirtualFile: 'homefolder.zip'
        jdkDestinationDirectory: '$(agent.toolsDirectory)/jdk14'
        cleanDestinationDirectory: false
    

    Result: enter image description here