Invoke the Azure DevOps API from within your Azure DevOps pipeline

Tim Deschryver

Our team is migrating existing codebases that's living in multiple repositories, to a single repository, a monorepository. This has been great and it improves our daily flow. From the start after migrating our first two repositories it added some benefits:


To keep our builds fast we're only building what's affected by the commits

But after migrating more reposities it became harder to keep track of the open pull requests. Multiple teams are now using the same repository, resulting that more pull requests are created. This means that knowing which pull requests are important to you and your team becomes a skill.

As a work around, we ping our team members to review our code, write a custom query to find open pull request, or we can manually assign a team as a reviewer. With the latter, the pull request is also added to your dashboard view in Azure DevOps. Your Azure DevOps dashboard shows your own pull requests, and the pull requests where you (or the team that you're in) are added as a reviewer. While adding reviewers manually can help, some pull requests can still remain open for a longer time because we forgot to assign a reviewer, and thus isn't visible to anyone. This is counter-productive because pull requests remain open, and because it takes up (recurring) time during the daily stand-ups when we ask for a status update.

As a solution to this problem we came up using our Azure DevOps pipeline combined with the Azure DevOps Api to automatically assign the corresponding team as a reviewer. Yes, Azure DevOps has a couple of default settings to automatically add reviewers to pull requests, but none of them did what we needed for our case. Our case might be slightly different than most (mono)repositories because a team is allowed to touch all the files that it needs within our repository.

To know which team that needs to be assigned, we agreed to prefix our branchnames with the team name, e.g. team-one/feature-a, or team-two/fix-bug. Using this branch group also has the befenift that the branches are now grouped within the branches overview page, which makes it easier to know what the teams are working on.

We wrote the powershell script below to add automatically detect the reviewer's team based on the branchname. Then it uses of the Azure DevOps API to add the team as a reviewer to the pull request. You can also see that the script uses environment variables that are passed to the script from the pipeline, for example an access token to invoke the rest request.

To only notify te team about this pull request when the build passes, we've choosen to add this stage as the last step in the pipeline. The template looks like this:

So far this is a simple solution, but if it's needed it can be extended further. For example, some things that can be added:

Outgoing links

Feel free to update this blog post on GitHub, thanks in advance!

Join My Newsletter (WIP)

Join my weekly newsletter to receive my latest blog posts and bits, directly in your inbox.

Support me

I appreciate it if you would support me if have you enjoyed this post and found it useful, thank you in advance.

Buy Me a Coffee at PayPal logo

Share this post on

Twitter LinkedIn