0

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:

enter image description here

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.

2
  • There is an explicit Azure CLI task in Azure Pipelines, which you could use. Also, stackoverflow.com/questions/66509534/… may be relevant. Note restarting the agent service/machine is required? Commented May 31, 2023 at 10:25
  • Thanks for your response. I test the restart solution and it's not the answer. about AzureCLL task I try with version 2 and it's not working either. I will try version 1 and come back. Commented May 31, 2023 at 10:51

1 Answer 1

1

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.

enter image description here

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. enter image description here

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. enter image description here If the AZ CLI path is not present, add it to the system variables and verify again.

Sign up to request clarification or add additional context in comments.

1 Comment

If you are installing Azure CLI on a self-hosted agent and your pipelines are still throwing errors, be sure to restart the Azure Host Agent to pick up the changes in the PATH variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.