Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
98a80c3
Added AzureCLIV3
tpavlovi Aug 15, 2025
320ac3f
Added two missing files
tpavlovi Aug 15, 2025
3393e9a
Added AuthSchemeNotSupported
tpavlovi Aug 15, 2025
cebdbff
Changed version
tpavlovi Aug 18, 2025
4feb850
Readme.md file has been updated
tpavlovi Aug 18, 2025
b19ead1
Added L0 tests
tpavlovi Aug 21, 2025
3723d89
Added check for whether the extension is installed
tpavlovi Aug 21, 2025
c1d979c
Added L0 tests
tpavlovi Aug 22, 2025
ff88075
Quotation marks were removed from the configuration reset command
tpavlovi Sep 4, 2025
2bbe16e
bumped task version
v-schhabra Nov 20, 2025
97376a1
Merge branch 'master' into users/tpavlovi/azureCLIV3
v-schhabra Nov 20, 2025
07105dd
replacing AzureCLIV2 with AzureCLIV3
v-schhabra Nov 25, 2025
e9b6747
Merge branch 'users/tpavlovi/azureCLIV3' of https://github.com/micros…
v-schhabra Nov 25, 2025
a8ab7fc
updated readme file
v-schhabra Nov 28, 2025
0bce694
Merge branch 'master' into users/tpavlovi/azureCLIV3
v-schhabra Nov 28, 2025
f43da77
improved error message
v-schhabra Dec 1, 2025
07c1e86
Merge branch 'users/tpavlovi/azureCLIV3' of https://github.com/micros…
v-schhabra Dec 1, 2025
c4f8995
added unit test
v-schhabra Dec 1, 2025
743ab4b
Merge branch 'master' into users/tpavlovi/azureCLIV3
v-schhabra Dec 1, 2025
ce349aa
Merge branch 'master' of https://github.com/microsoft/azure-pipelines…
v-schhabra Dec 2, 2025
17125f8
updated test cases to remove hardcoded paths
sanjays-ms Dec 2, 2025
83bbc50
Add environment variables for job and project context in test files
sanjays-ms Dec 2, 2025
8c0990d
Add mocks for Utility and ScriptType in Azure CLI test files
sanjays-ms Dec 2, 2025
e626e33
Refactor Utility and ScriptType mocks in Azure CLI test files for imp…
sanjays-ms Dec 2, 2025
39895e0
fixing test case
v-schhabra Dec 3, 2025
871663b
fixing test cases
v-schhabra Dec 3, 2025
b7daaf8
fix test case
v-schhabra Dec 3, 2025
2f79ba6
Merge branch 'master' into users/v-sanjayse/fix-azurecliv3-tests
v-schhabra Dec 3, 2025
3579bd9
fix test case
v-schhabra Dec 3, 2025
93eec62
Merge branch 'users/v-sanjayse/fix-azurecliv3-tests' of https://githu…
v-schhabra Dec 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Tasks/AzureCLIV1/ @microsoft/release-management-task-team @manolerazvan

Tasks/AzureCLIV2/ @microsoft/release-management-task-team @manolerazvan

Tasks/AzureCLIV3/ @microsoft/release-management-task-team @manolerazvan

Tasks/AzureCloudPowerShellDeploymentV1/ @microsoft/release-management-task-team @manolerazvan

Tasks/AzureCloudPowerShellDeploymentV2/ @microsoft/release-management-task-team @manolerazvan
Expand Down
5 changes: 5 additions & 0 deletions Tasks/AzureCLIV3/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scripts-prepend-node-path=true

registry=https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/

always-auth=true
70 changes: 70 additions & 0 deletions Tasks/AzureCLIV3/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Azure CLI

## Overview
This task supports running [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/overview) commands on Cross platform agents running Windows, Linux or Mac.

### What's new in Version 3.0
- Azure DevOps service connections support with automatic CLI extension installation
- Workload Identity Federation support for Azure DevOps connections
- Automatic organization and project configuration from pipeline context

## Contact Information
Please report a problem at [Developer Community Forum](https://developercommunity.visualstudio.com/spaces/21/index.html) if you are facing problems in making this task work. You can also share feedback about the task like, what more functionality should be added to the task, what other tasks you would like to have, at the same place.

## Pre-requisites for the task
The following pre-requisites need to be setup in the target machine(s) for the task to work properly.

#### **Azure Subscription**
To deploy to Azure, an Azure subscription has to be linked to Team Foundation Server or to Azure Pipelines using the Services tab in the settings section. Add the Azure subscription to use in the Build or Release Management definition by opening the Account Administration screen (gear icon on the top-right of the screen) and then click on the Services Tab.
- For Azure Classic resources use 'Azure' endpoint type with Certificate or Credentials based authentication. If you are using credentials based auth, ensure that the credentials are for a [**work account**](https://azure.microsoft.com/en-in/pricing/member-offers/msdn-benefits-details/work-accounts-faq/) because Microsoft accounts like [**joe@live.com**](https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/DeployAzureResourceGroup) or [**joe@hotmail.com**](https://github.com/Microsoft/azure-pipelines-tasks/blob/master/Tasks/DeployAzureResourceGroup) are not supported.
- For [ARM](https://azure.microsoft.com/en-in/documentation/articles/resource-group-overview/), use 'Azure Resource Manager' endpoint type, for more details follow the steps listed in the link [here](https://go.microsoft.com/fwlink/?LinkID=623000&clcid=0x409).

#### **Azure DevOps Service Connection**
For Azure DevOps CLI operations, you can use Azure DevOps service connections with Workload Identity Federation authentication. This allows secure access to Azure DevOps resources. The task will automatically install and configure the Azure DevOps CLI extension when using this connection type.

#### **Azure CLI**
The task needs the Azure CLI version to be installed on the automation agent, and the details are available [here](https://azure.microsoft.com/en-us/documentation/articles/xplat-cli-install/).
If an agent is already running on the machine on which the Azure CLI is installed, ensure to restart the agent to ensure all the relevant environment variables are updated.

## Parameters of the task
The task is used to run Azure CLI commands on Cross platform agents running Windows, Linux or Mac . The mandatory fields are highlighted with a *.

* **Connection Type**\*: Select the type of service connection to use. Choose 'Azure Resource Manager' for Azure Resource Manager service connections or 'Azure DevOps' for Azure DevOps service connections.

* **Azure Resource Manager Connection**\*: Select the Azure Resource Manager service connection. This field is visible when Connection Type is set to 'Azure Resource Manager'.

* **Azure DevOps Service Connection**\*: Select an Azure DevOps service connection. This field is visible when Connection Type is set to 'Azure DevOps'.

* **Script Type**\*: Select the type of script to be executed on the agent. Task supports four types: Batch / Shell / PowerShell / PowerShell Core scripts, default selection being empty. Select Shell/PowerShell Core script when running on Linux agent or Batch/PowerShell/PowerShell Core script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows)

* **Script Location**\*: Select the mode of providing the script. Task supports two modes: one as a Script Path to a linked artifact and another as an inline script, default selection being the "Script Path"

* **Script Path**\*: When using Windows based agent, specify the path to the .bat , .cmd , .ps1 script whereas when using Linux based agent, specify the path to the .sh , .ps1 script you want to run. The path must be a fully qualified path or a valid path relative to the default working directory. Note: You must also specify the respective script type in above field.

* **Inline Script**\*: Specify the script inline here. When using Windows based agent use batch or PowerShell or PowerShell Core scripting whereas use shell or PowerShell Core scripting when using Linux based agents. Note: You must also specify the respective script type in above field.

* **Script Arguments**: Specify arguments to pass to the script.

* **Working folder**: Specify the working directory in which you want to run the script. If you leave it empty, the working directory is the folder where the script is located.

* **Fail on standard error**: Select this check box if you want the build to fail if errors are written to the StandardError stream.

* **Access service principal details in script**: Select this check box if you want to add service principal id , service principal key and tenantId of the Azure endpoint to the script's execution environment. You can use variables: `servicePrincipalId`, `servicePrincipalKey` and `tenantId` in your script. This is honored only when the Azure endpoint has Service Principal authentication scheme. \
\
Syntax to access environment variables based on script type.\
*Powershell script:* `$env:servicePrincipalId`\
*Batch script:* `%servicePrincipalId%` \
*Shell script:* `$servicePrincipalId`

* **ErrorActionPreference**: Select this checkbox if you want the task to fail when any errors are written to the StandardError stream. If you leave it unchecked, standard errors will be ignored and only exit codes will be used to determine the status.

* **Use global Azure CLI configuration**: If this is unchecked, the task will use its own separate Azure CLI configuration directory. This allows Azure CLI tasks to run in parallel during releases.

* **Working Directory**: Current working directory where the script is run. If left blank, this input is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory).

* **LASTEXITCODE**: If this input is false, the line if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LASTEXITCODE } is appended to the end of your script. This will propagate the last exit code from an external command as the exit code of PowerShell. Otherwise, the line is not appended to the end of your script.

* **az login output visibility**: If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output.

* **Keep Azure CLI session active**: When enabled, this task will continuously sign into Azure to avoid AADSTS700024 errors when requesting access tokens beyond the IdToken expiry date. Note that this feature is EXPERIMENTAL, may not work in all scenarios and you are using it without any guarantees. Valid only for service connections using the Workload Identity Federation authentication scheme.

67 changes: 67 additions & 0 deletions Tasks/AzureCLIV3/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"loc.friendlyName": "Azure CLI",
"loc.helpMarkDown": "[Learn more about this task](http://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/AzureCLIV3/Readme.md) or [see the Azure CLI documentation](https://docs.microsoft.com/cli/azure/)",
"loc.description": "Run Azure CLI commands against an Azure subscription in a PowerShell Core/Shell script when running on Linux agent or PowerShell/PowerShell Core/Batch script when running on Windows agent.",
"loc.instanceNameFormat": "Azure CLI $(scriptPath)",
"loc.releaseNotes": "What's new in Version 3.0:\n- Support for dual connection types: Azure Resource Manager and Azure DevOps service connections. \n- Azure DevOps CLI integration with automatic extension installation and configuration. \n- Workload Identity Federation support for Azure DevOps connections.",
"loc.group.displayName.advanced": "Advanced",
"loc.input.label.connectionType": "Connection Type",
"loc.input.help.connectionType": "Type of service connection to use",
"loc.input.label.connectedServiceNameARM": "Azure Resource Manager connection",
"loc.input.help.connectedServiceNameARM": "Select an Azure Resource Manager service connection for the deployment",
"loc.input.label.azureDevOpsServiceConnection": "Azure DevOps Service Connection",
"loc.input.help.azureDevOpsServiceConnection": "Select an Azure DevOps service connection",
"loc.input.label.scriptType": "Script Type",
"loc.input.help.scriptType": "Type of script: PowerShell/PowerShell Core/Bat/Shell script. Select Shell/PowerShell Core script when running on Linux agent or Batch/PowerShell/PowerShell Core script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows).",
"loc.input.label.scriptLocation": "Script Location",
"loc.input.help.scriptLocation": "Path to script: File path or Inline script",
"loc.input.label.scriptPath": "Script Path",
"loc.input.help.scriptPath": "Fully qualified path of the script(.ps1 or .bat or .cmd when using Windows based agent else .ps1 or .sh when using linux based agent) or a path relative to the the default working directory",
"loc.input.label.inlineScript": "Inline Script",
"loc.input.help.inlineScript": "You can write your scripts inline here. When using Windows agent, use PowerShell or PowerShell Core or batch scripting whereas use PowerShell Core or shell scripting when using Linux based agents. For batch files use the prefix \"call\" before every azure command. You can also pass predefined and custom variables to this script using arguments \n\n example for PowerShell/PowerShellCore/shell: \naz --version \naz account show \n\n example for batch:\ncall az --version \ncall az account show",
"loc.input.label.scriptArguments": "Script Arguments",
"loc.input.help.scriptArguments": "Arguments passed to the script",
"loc.input.label.powerShellErrorActionPreference": "ErrorActionPreference",
"loc.input.help.powerShellErrorActionPreference": "Prepends the line `$ErrorActionPreference = 'VALUE'` at the top of your powershell/powershell core script.",
"loc.input.label.addSpnToEnvironment": "Access service principal details in script",
"loc.input.help.addSpnToEnvironment": "Adds service principal id, service principal key and tenant id of the Azure endpoint you chose to the script's execution environment. You can use variables: `servicePrincipalId`, `servicePrincipalKey` and `tenantId` in your script.\n\nThis is honored only when the Azure endpoint has Service Principal authentication scheme.\n\nSyntax to access environment variables based on script type.\n\nPowershell script: $env:servicePrincipalId\n\nBatch script: %servicePrincipalId% \n\nShell script: $servicePrincipalId",
"loc.input.label.useGlobalConfig": "Use global Azure CLI configuration",
"loc.input.help.useGlobalConfig": "If this is false, this task will use its own separate [Azure CLI configuration directory](https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration?view=azure-cli-latest#cli-configuration-file). This can be used to run Azure CLI tasks in *parallel* releases",
"loc.input.label.cwd": "Working Directory",
"loc.input.help.cwd": "Current working directory where the script is run. Empty is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory)",
"loc.input.label.failOnStandardError": "Fail on Standard Error",
"loc.input.help.failOnStandardError": "If this is true, this task will fail when any errors are written to the StandardError stream. Unselect the checkbox to ignore standard errors and rely on exit codes to determine the status",
"loc.input.label.powerShellIgnoreLASTEXITCODE": "Ignore $LASTEXITCODE",
"loc.input.help.powerShellIgnoreLASTEXITCODE": "If this is false, the line `if ((Test-Path -LiteralPath variable:\\LASTEXITCODE)) { exit $LASTEXITCODE }` is appended to the end of your script. This will cause the last exit code from an external command to be propagated as the exit code of powershell. Otherwise the line is not appended to the end of your script.",
"loc.input.label.visibleAzLogin": "az login output visibility",
"loc.input.help.visibleAzLogin": "If this is set to true, az login command will output to the task. Setting it to false will suppress the az login output",
"loc.input.label.keepAzSessionActive": "[Experimental] Keep Azure CLI session active",
"loc.input.help.keepAzSessionActive": "When enabled, this task will continuously sign into Azure to avoid AADSTS700024 errors when requesting access tokens beyond the IdToken expiry date. Note that this feature is EXPERIMENTAL, may not work in all scenarios and you are using it without any guarantees. Valid only for service connections using the Workload Identity Federation authentication scheme.",
"loc.messages.ScriptReturnCode": "Script exited with return code: %d",
"loc.messages.ScriptFailed": "Script failed with error: %s",
"loc.messages.ScriptFailedStdErr": "Script has output to stderr. Failing as failOnStdErr is set to true.",
"loc.messages.ScriptFailedWithExitCode": "Script failed with exit code: %d",
"loc.messages.UnsupportedEndpointScheme": "Unsupported service connection authorization scheme: Service Principal for AzureRM",
"loc.messages.AzureSDKNotFound": "Azure CLI 2.x is not installed on this machine.",
"loc.messages.FailedToLogout": "The following error occurred while logging out: %s",
"loc.messages.LoginFailed": "Azure login failed",
"loc.messages.MSILoginFailed": "Azure login failed using Managed Service Identity",
"loc.messages.AuthSchemeNotSupportedForAzureRM": "The authentication scheme '%s' is not supported for Azure Resource Manager connections. Please update your Azure Resource Manager service connection to use one of the supported schemes: Service Principal, Workload Identity Federation (WIF), or Managed Identity.",
"loc.messages.AuthSchemeNotSupportedForAzureDevOps": "The authentication scheme '%s' is not supported for Azure DevOps service connections. Please update your Azure DevOps service connection to use one of the supported schemes: Workload Identity Federation. ",
"loc.messages.ErrorInSettingUpSubscription": "Error in setting up subscription",
"loc.messages.SettingAzureConfigDir": "Setting AZURE_CONFIG_DIR env variable to: %s",
"loc.messages.SettingAzureCloud": "Setting active cloud to: %s",
"loc.messages.JS_InvalidFilePath": "Script file could not be found at specified script location: '%s'. Please verify the script exists at the specified path. If you want to use inline script, specify input `Script Location` as `inlineScript`.",
"loc.messages.JS_InvalidErrorActionPreference": "Invalid ErrorActionPreference '%s'. The value must be one of: 'Stop', 'Continue', or 'SilentlyContinue'",
"loc.messages.GlobalCliConfigAgentVersionWarning": "For agent version < 2.115.0, only global Azure CLI configuration can be used",
"loc.messages.UnacceptedScriptLocationValue": "%s is not a valid value for task input 'Script Location' (scriptLocation in YAML). Value can either be'inlineScript' or 'scriptPath'",
"loc.messages.ExpiredServicePrincipalMessageWithLink": "Secret expired, update service connection at %s See https://aka.ms/azdo-rm-workload-identity-conversion to learn more about conversion to secret-less service connections.",
"loc.messages.ProxyConfig": "az tool is configured to use %s as proxy server",
"loc.messages.FailedToRefreshAzSession": "The following error occurred while trying to refresh az-cli session: %s",
"loc.messages.RefreshingAzSession": "Attempting to refresh az-cli session...",
"loc.messages.KeepingAzSessionActiveUnsupportedScheme": "The 'keepAzSessionActive' input might be used only for workload identity federation ARM service connection. The referenced service endpoint auth scheme was unexpected: %s. Change the scheme or remove 'keepAzSessionActive' input.",
"loc.messages.FailedToInstallAzureDevOpsCLI": "Failed to install Azure DevOps CLI extension",
"loc.messages.FailedToLoginAzureDevOpsCLI": "Failed to login to Azure DevOps CLI",
"loc.messages.FailedToSetAzureDevOpsOrganization": "Failed to set Azure DevOps organization",
"loc.messages.FailedToSetAzureDevOpsProject": "Failed to set Azure DevOps project"
}
3 changes: 3 additions & 0 deletions Tasks/AzureCLIV3/Tests/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
registry=https://pkgs.dev.azure.com/mseng/PipelineTools/_packaging/PipelineTools_PublicPackages/npm/registry/

always-auth=true
Loading