Git & Branch Policy Command Line Tool

This tool was created to make it easier to script certain configuration changes when working with Git in Azure Dev Ops, and in particular the various branch policies. Although in many cases these can be set using the Azure Dev Ops UI, the underlying API is more powerful. The 'AZDO' command can provide information about and/or configure the following:

  • Git Repositories
  • Build Definitions
  • Branch Policies

All commands require --url --project and --auth parameters, they have been omitted in the examples for brevity.


    azdo [builddef | policy | repo] --url (Azure DevOps url) --project (Azure DevOps Project Name) --auth (Personal Access Token)

Git Repositories

List all repositories in the specified project


    azdo repo list 

Create a new repository in the specified project


    azdo repo create --repo NewRepoName

Build Definitions

List all build definitions in the specified project


    azdo builddef list 

Branch Policies

List all branch policies in the specified project


    azdo policy list 

Delete a specific branch policy in the specified project


    azdo policy delete --policyId 12345

Delete all branch policies in the specified project


    azdo policy deleteall

Unlike creating policies through the Azure DevOps UI, the branch parameter allows you to make the policy apply to branches in any repository. This is useful if you want the policy to apply to any develop or master branch, for all existing and future repos. If done through the UI, you would need to create the policy manually for every new repo you create.

Create 'minimum approvers' branch policy for all 'develop' branches, requiring a minimum of two approvers for pull requests.


    azdo policy approvers --approvers 2 --branch develop

Create a branch policy that requires pull requests to be linked to a work item for all 'master' branches.


    azdo policy workitem --branch master

Create a branch policy that requires pull requests to have a successful build for feature branch called 'my-feature'.


    azdo policy build --branch "feature/my-feature" --repo MyRepoName --build "My Build Pipeline Name" 

Create a branch policy that requires all review comments to be resolved for all develop branches.


    azdo policy resolvecomments --branch develop

Create a branch policy to use 'Squash Commit' merge strategy for all develop branches.


    azdo policy mergestrategy --branch develop

Create a branch policy to restrict maximum blob file size (in bytes) for the specified repository.


    azdo policy filesize --repo MyRepoName --maxsize 1024000

Disclaimer

This program is free software: you can redistribute it freely providing it is not reverse engineered or modified in any way. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is used entirely at your own risk. You should perform tests on non-critical data before using in a live environment.

Download

Download the latest version here.