az login using Azure CLI agent on Azure Devops

SARASWAT CHETAN 91 Reputation points
2021-05-06T17:25:28.637+00:00

I am trying to run az login and then further some other az commands via a powershell script or bash or either using Azure CLI as agent in Azure Devops release pipeline, however every time it is stopping at "az login " itself, asking to do a "login" using the link opened via the browser.
https://login.microsoftonline.com/common/oauth2/authorize
However the script is running under the agent's IR and cannot be used to run the browser window.
I also tried to login using "az login --use-device-code" and then opened the browser using the code value and it still failed.

Is there a way i can perform "az login" using any of the agents so the browser picks my managed identity or do I have to login via a "Service Principal" only.

Kindly someone advise so that i can use any of the agents to run az login successfully.

Community Center Not monitored
0 comments No comments
{count} votes

Accepted answer
  1. JamesTran-MSFT 36,906 Reputation points Microsoft Employee Moderator
    2021-05-07T22:14:36.22+00:00

    @SARASWAT CHETAN
    Thank you for your post!

    When it comes to logging into Azure via CLI without a pop-up window, you should be able to use:

    az login -u ******@contoso.com -p VerySecret  
    #Optionally, you can specify a tenant using --tenant contoso.onmicrosoft.com  
    

    For more info - https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az_login

    94848-azloginnopopup.gif

    Additional Link:
    login to azure account without popup using PowerShell

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.