Contents

Azure DevOps CLI – Control Azure DevOps in Command Line

Do you want to interact with Azure DevOps using a command line, or automate a task to run to carry out Azure DevOps tasks?

Azure DevOps has a Command Line Interface; this enables you not to worry about calling the Azure DevOps REST Web Services.

How to Get Started?

First things first, you need to install Azure Cloud Shell. Depending on which operating system you are using, there are different instructions. The following link https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest will give you the instructions for your operating system. Below are the commands for Windows Powershell.

1
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'

Next step is to install the extension for Azure DevOps.

1
az extension add --name azure-devops

List the extensions that are installed.

1
az extension list table

Now if you are always working on the same Project / Organisation it is best to set some defaults. You don’t have to set both Organisation or Project’

1
az devops configure --defaults organization=https://dev.azure.com/Azure-DevOps-Tips/  

Next step is to login you have two approaches

Login to Azure

1
az login

Your default browser will open and you will have to login with you Azure DevOps credentials.

Use the PAT code

If you don’t have a PAT code already you will need to create one follow the following steps. In your Azure DevOps organisation you want to access. Click on the profile icon highlighted below with (1) on the top right of the browser. Then click on Personal Access Tokens menu item.

/azure-cli/image1.png

On the Personal Access Tokens screen click on the New Token as highlighted below.

/azure-cli/image2.png

Tip
When creating a PAT Code you may be tempted to select Full Control. But if someone gets hold of your PAT code then they will have full control of your Azure DevOps until you revoke the token, regenerate the Token or the expiry date is reached. So if you just wants to create Work Items with the CLI only select Read & Write Work Items Scope.

Now What?

So now with Azure DevOps CLI installed you can manage your Azure DevOps Organisations

CommandDescription
az devopsManage Organisation Level
az pipelineManage Azure DevOps Pipelines
az boardsManage Azure DevOps Boards
az reposManage Azure DevOps Repositories
az artifactsManage Azure DevOps Artifacts
az devops projectManage Azure DevOps Projects
az develop securityManage Azure DevOps Security
az devops teamsManage Azure DevOps Teams
az devops userManage Azure DevOps Users
az devops wikiManage Azure DevOps Wikis
az devops extensionsManage Azure DevOps Extensions

Please note at the time of writing you can’t use the Azure DevOps tools against a Public project when you aren’t a member of that project.

Tip

You can now automate creating your next azure devops project. If you need to create a script and don’t want to be prompted for PAT code there are two options.

  1. Use a environment variable – $env:AZURE_DEVOPS_EXT_PAT = ‘xxxxxxx’
  2. Get the PAT code from a file cat my_pat_token.txt | az devops login –organization https://dev.azure.com/azure-devops-tips