I installed Azure cli
on a Windows Server Agent
and it works fine in cmd
/PowerShell
. but when I want to use Azure cli
on PowerShell
task in Azure Pipeline
it's not working.
the error message is: 'az' is not recognized as an internal or external command.
cmd
example on agent:
task code sample on Azure Pipeline
:
- powershell: |
echo "*********" | az devops login --organization https://dev.azure.com/*****
displayName: 'Login on Azure CLI
I check Path
environment variable and even update variables in pipeline to ensure everything fine but nothing changes.
I have followed the below steps to execute az
command from the azure pipeline. Check if you have followed all these steps and able to ressolve the issue.
Firstly I used the below command to install Azure CLI on a windows machine.
$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest -Uri https://azcliprod.blob.core.windows.net/msi/azure-cli-2.49.0.msi -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; Remove-Item .\AzureCLI.msi
Next I installed the devops agent on VM with following configuration.
When configuring the pipeline, ensure you select the correct agent pool. In my case it is default
.
To test, add a powershell task task pipeline with command az login --service-principal -u $(appid) -p $(passwd) --tenant $(tenant)
. Run the pipeline and verify the output.
If you still encounter issues, check the environment variable path to verify if the AZ CLI path is included. You can run echo $env:PATH
from the pipeline to check.
If the AZ CLI path is not present, add it to the system variables and verify again.