Azure CLI task

Azure Pipelines

Use this task to run a shell or batch script containing Azure CLI commands against an Azure subscription.

This task is used to run Azure CLI commands on cross-platform agents running on Linux, macOS, or Windows operating systems.

What's new in Version 2.0

  • Supports running PowerShell and PowerShell Core script
  • PowerShell Core script works with Xplat agents (Windows, Linux or OSX), make sure the agent has PowerShell version 6 or higher
  • PowerShell script works only with Windows agent, make sure the agent has PowerShell version 5 or lower


  • A Microsoft Azure subscription

  • Azure Resource Manager service connection to your Azure account

  • Microsoft hosted agents have Azure CLI pre-installed. However if you are using private agents, install Azure CLI on the computer(s) that run the build and release agent. If an agent is already running on the machine on which the Azure CLI is installed, restart the agent to ensure all the relevant stage variables are updated.

Task Inputs

Parameters Description
Azure subscription
(Required) Select an Azure resource manager subscription for the deployment. This parameter is shown only when the selected task version is 0.* as Azure CLI task v1.0 supports only Azure Resource Manager (ARM) subscriptions
Script Type
(Required) Type of script: PowerShell/PowerShell Core/Bat/Shell script. Select bash/pscore script when running on Linux agent or batch/ps/pscore script when running on Windows agent. PowerShell Core script can run on cross-platform agents (Linux, macOS, or Windows)
Script Location
(Required) Path to script: File path or Inline script
Default value: scriptPath
Script Path
(Required) 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 default working directory
Inline Script
(Required) 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.
Example for PowerShell/PowerShellCore/shell: az --version az account show
Example for batch: call az --version call az account show
Script Arguments
(Optional) Arguments passed to the script
(Optional) Prepends the line $ErrorActionPreference = 'VALUE' at the top of your powershell/powershell core script
Default value: stop
Access service principal details in script
(Optional) Adds service principal id and key of the Azure endpoint you chose to the script's execution environment. You can use these variables: $env:servicePrincipalId, $env:servicePrincipalKey and $env:tenantId in your script. This is honored only when the Azure endpoint has Service Principal authentication scheme
Default value: false
Use global Azure CLI configuration
(Optional) If this is false, this task will use its own separate Azure CLI configuration directory. This can be used to run Azure CLI tasks in parallel releases"
Default value: false
Working Directory
(Optional) Current working directory where the script is run. Empty is the root of the repo (build) or artifacts (release), which is $(System.DefaultWorkingDirectory)
Fail on Standard Error
(Optional) 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
Default value: false
(Optional) 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
Default value: false


Following is an example of a YAML snippet which lists the version of Azure CLI and gets the details of the subscription.

- task: AzureCLI@2
  displayName: Azure CLI
    azureSubscription: <Name of the Azure Resource Manager service connection>
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
      az --version
      az account show

Open source

This task is open source on GitHub. Feedback and contributions are welcome.


Do I need an agent?

You need at least one agent to run your build or release.

I'm having problems. How can I troubleshoot them?

See Troubleshoot Build and Release.

I can't select a default agent pool and I can't queue my build or release. How do I fix this?

See Agent pools.