Another long title for a relatively short article.
In case you aren’t aware, the az cli has a great extension for Azure DevOps and supports automatically logging you in to the devops extension when you use az login. Very helpful and simple, no need to manually issue a PAT through the Azure DevOps portal.
Now, what about the scenario when you need a PAT to make a rest call to Azure DevOps? There are some scenarios that the devops az cli extension does not cover (such as queuing a yaml pipeline with parameters).
Here is a quick and easy PowerShell script to get you a PAT:
Note that there is not much documentation on using this mechanism with the az cli. I was able to work this out due to my previous experience obtaining an Azure Databricks token using the same command.
This is about as close as I can find to anything official: https://github.com/microsoft/azure-devops-auth-samples/blob/master/PersonalAccessTokenAPIAppSample/app_config.py
3 Replies to “How To Get a PAT (Personal Access Token) for Azure DevOps from the az cli”
How did you get the Resource ID?
Is this only for self hosted versions where you can get this ID?
Hey Chris, I used Fiddler to watch the traffic when using the
az devopscommands. I was able to pick out the resource id from there. I had some previous experience with using the Azure CLI in this fashion when working with Azure Databricks (see Alexandre’s helpful Azure Databricks article).