JavaToolInstaller@1 - Java tool installer v1 task
Acquire a specific version of Java from a user-supplied Azure blob or the tool cache and sets JAVA_HOME.
Syntax
# Java tool installer v1
# Acquire a specific version of Java from a user-supplied Azure blob or the tool cache and sets JAVA_HOME.
- task: JavaToolInstaller@1
inputs:
versionSpec: '8' # string. Required. JDK version. Default: 8.
jdkArchitectureOption: # 'x64' | 'x86'. Required. JDK architecture.
jdkSourceOption: # 'AzureStorage' | 'LocalDirectory' | 'PreInstalled'. Required. JDK source.
#jdkFile: # string. Required when jdkSourceOption == LocalDirectory. JDK file.
#azureResourceManagerEndpoint: # string. Required when jdkSourceOption == AzureStorage. Azure subscription.
#azureStorageAccountName: # string. Required when jdkSourceOption == AzureStorage. Storage account name.
#azureContainerName: # string. Required when jdkSourceOption == AzureStorage. Container name.
#azureCommonVirtualFile: # string. Required when jdkSourceOption == AzureStorage. Common virtual path.
#jdkDestinationDirectory: # string. Required when jdkSourceOption != PreInstalled. Destination directory.
#azureResourceGroupName: # string. Optional. Use when jdkSourceOption == AzureStorage. Resource Group name.
#cleanDestinationDirectory: true # boolean. Optional. Use when jdkSourceOption != PreInstalled. Clean destination directory. Default: true.
#createExtractDirectory: true # boolean. Optional. Use when jdkSourceOption != PreInstalled. Create directory for extracting. Default: true.
Inputs
versionSpec
- JDK version
string
. Required. Default value: 8
.
Specifies the JDK version to make available on the path. Use a whole number version, such as 10.
jdkArchitectureOption
- JDK architecture
string
. Required. Allowed values: x64
, x86
.
Specifies the architecture (x86
, x64
) of the JDK.
jdkSourceOption
- JDK source
string
. Required. Allowed values: AzureStorage
(Azure Storage), LocalDirectory
(Local Directory), PreInstalled
(Pre-installed).
Specifies the source for the compressed JDK. The source can be Azure blob storage or a local directory on the agent or source repository, or you can use the pre-installed version of Java (available for Microsoft-hosted agents). Please see the example below about how to use the pre-installed version of Java.
Note
This version of the task accesses Azure storage using an Azure Resource Manager service connection configured using workload identity federation and Azure RBAC. For more information, see Assign an Azure role for access to blob data.
jdkFile
- JDK file
string
. Required when jdkSourceOption == LocalDirectory
.
Specifies the path to the JDK archive file that contains the compressed JDK. The path could be in your source repository or a local path on the agent. The file should be an archive (.zip, .tar.gz, .7z) containing the bin folder on the root level or inside a single directory. MacOS supports .pkg and .dmg files containing only one .pkg file inside.
azureResourceManagerEndpoint
- Azure subscription
string
. Required when jdkSourceOption == AzureStorage
.
Specifies the Azure Resource Manager subscription for the JDK.
azureStorageAccountName
- Storage account name
string
. Required when jdkSourceOption == AzureStorage
.
Specifies Azure Classic or Resource Manager storage accounts. Select the storage account name in which the JDK is located.
azureContainerName
- Container name
string
. Required when jdkSourceOption == AzureStorage
.
Specifies the name of the container in the storage account where the JDK is located.
azureCommonVirtualFile
- Common virtual path
string
. Required when jdkSourceOption == AzureStorage
.
Specifies the path to the JDK inside the Azure storage container.
jdkDestinationDirectory
- Destination directory
string
. Required when jdkSourceOption != PreInstalled
.
Specifies the destination directory where the JDK should be extracted. On Linux and Windows, this is used as the destination directory for the JDK installation. On macOS, this directory is used as a temporary folder for extracting .dmg's because macOS doesn't support installing JDK to a specific directory.
azureResourceGroupName
- Resource Group name
string
. Optional. Use when jdkSourceOption == AzureStorage
.
Resource Group name of the storage account.
cleanDestinationDirectory
- Clean destination directory
boolean
. Optional. Use when jdkSourceOption != PreInstalled
. Default value: true
.
Specifies the option to clean the destination directory before JDK is extracted into it.
createExtractDirectory
- Create directory for extracting
boolean
. Optional. Use when jdkSourceOption != PreInstalled
. Default value: true
.
By default, the task creates a directory similar to JAVA_HOME_8_X64_OpenJDK_zip
for extracting JDK. This option disables the creation of that folder and, if set to false
, JDK is located in the root of jdkDestinationDirectory
instead.
Task control options
All tasks have control options in addition to their task inputs. For more information, see Control options and common task properties.
Output variables
None.
Remarks
Use this task to acquire a specific version of Java from a user-supplied Azure blob, a location in the source or on the agent, or the tools cache. The task also sets the JAVA_HOME
environment variable.
Use this task to change the version of Java used in Java tasks.
Note
To run the Java Tool Installer task on macOS, it is required for the user under which the agent is running to have permission to execute the sudo command without a password. You can follow the next steps to enable this permission:
- Run the sudo visudo command. The sudoers file opens for editing.
- Go to the bottom of the file and add the following line:
user ALL=NOPASSWD: /usr/sbin/installer
(Replace user with the actual user alias).- Save and close the file.
Examples
Here's an example of getting the archive file from a local directory on Linux. The file should be an archive (.zip, .gz) of the JAVA_HOME
directory, so it includes the bin
, lib
, include
, jre
, etc. directories.
- task: JavaToolInstaller@1
inputs:
versionSpec: "11"
jdkArchitectureOption: x64
jdkSourceOption: LocalDirectory
jdkFile: "/builds/openjdk-11.0.2_linux-x64_bin.tar.gz"
jdkDestinationDirectory: "/builds/binaries/externals"
cleanDestinationDirectory: true
Here's an example of downloading the archive file from Azure Storage.
The file should be an archive (.zip, .gz) of the JAVA_HOME
directory, so it includes the bin
, lib
, include
, jre
, etc. directories.
Note
This version of the task accesses Azure storage using an Azure Resource Manager service connection configured using workload identity federation and Azure RBAC. For more information, see Assign an Azure role for access to blob data.
- task: JavaToolInstaller@1
inputs:
versionSpec: '6'
jdkArchitectureOption: 'x64'
jdkSourceOption: AzureStorage
azureResourceManagerEndpoint: myARMServiceConnection
azureStorageAccountName: myAzureStorageAccountName
azureContainerName: myAzureStorageContainerName
azureCommonVirtualFile: 'jdk1.6.0_45.zip'
jdkDestinationDirectory: '$(agent.toolsDirectory)/jdk6'
cleanDestinationDirectory: false
Here's an example of using "pre-installed" feature. This feature allows you to use Java versions that are pre-installed on the Microsoft-hosted agent. You can find available pre-installed versions of Java in the included software column in the hosted agents table.
- task: JavaToolInstaller@1
inputs:
versionSpec: '8'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
Requirements
Requirement | Description |
---|---|
Pipeline types | YAML, Classic build, Classic release |
Runs on | Agent, DeploymentGroup |
Demands | None |
Capabilities | Running this task satisfies the following demands for any subsequent tasks in the same job: Java, JDK |
Command restrictions | This task runs using the following command restrictions: restricted |
Settable variables | This task has permission to set the following variables: PATH, JAVA_HOME* |
Agent version | 2.182.1 or greater |
Task category | Tool |