Azure CLI task
Use this task in a build or release pipeline 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.
This task is under development. If you encounter problems, or wish to share feedback about the task and features you would like to see, please contact us.
What's new in Version 1.0
- Supports the new AZ CLI 2.0, which is Python based
- Works with agents on Linux, macOS, and Windows
- To work with Azure CLI 1.0, which is node based, switch to task version 0.0
- Both versions of Azure-CLI can coexist in the same system, but task V1.0 logs into the Python based AZ CLI using the user's subscription, whereas task V0.0 logs into the node based Azure CLI. Therefore, scripts should include only the appropriate corresponding commands.
- No support for Classic subscriptions. AZ CLI 2.0 supports only Azure Resource Manager (ARM) subscriptions
- Currently, Microsoft-hosted agents do not have the AZ CLI installed. You can either install it using
npm install -g azure-cli(on Microsoft-hosted Linux agents, use
sudo npm install -g azure-cli) or use a self-hosted agent with the AZ CLI pre-installed.
- A Microsoft Azure subscription
- A service connection to your Azure account. You can use either:
- Azure CLI installed on the computer(s) that run the build and release agent. See Install the Azure CLI. 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.
# Azure CLI # Run Azure CLI commands against an Azure subscription in a Shell script when runnning on Linux agent or Batch script when running on Windows agent. - task: AzureCLI@1 inputs: azureSubscription: #scriptLocation: 'scriptPath' # Options: inlineScript, scriptPath #scriptPath: # Required when scriptLocation == ScriptPath #inlineScript: # Required when scriptLocation == InlineScript #arguments: # Optional #addSpnToEnvironment: false # Optional #useGlobalConfig: false # Optional #workingDirectory: # Optional #failOnStandardError: false # Optional
|Azure Connection Type||Required. Select the type of service connection used to define the connection to Azure. Choose Azure Classic or Azure Resource Manager. 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.|
|Azure Classic Subscription||Required if you select Azure Classic for the Azure Connection Type parameter. The name of an Azure Classic service connection configured for the subscription where the target Azure service, virtual machine, or storage account is located.|
|Azure RM Subscription||Required if you select Azure Resource Manager for the Azure Connection Type parameter. The name of an Azure Resource Manager service connection configured for the subscription where the target Azure service, virtual machine, or storage account is located. See Azure Resource Manager overview for more details.|
|Script Location||Required. The way that the script is provided. Choose Inline Script or Script Path (the default).|
|Inline Script||Required if you select Inline Script for the Script Location parameter. Type or copy the script code to execute here. You can include default variables, global variables, and stage variables.|
|Script Path||Required if you select Script Path for the Script Location parameter. The path to a linked artifact that is the .bat, .cmd, or .sh script you want to run. It can be a fully-qualified path, or a valid path relative to the default working directory.|
|Arguments||Optional. Any arguments you want to pass to the script.|
|Advanced - Working Directory||Optional. The working directory in which the script will execute. If not specified, this will be the folder containing the script file.|
|Advanced - Fail on Standard Error||Set this option if you want the build to fail if errors are written to the StandardError stream.|
|Control options||See Control options|
This task is open source on GitHub. Feedback and contributions are welcome.
Q & A
Do I need an agent?
You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.
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.
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.