Azure Repos Pull Request Comment with Latest Build Artifact Download Link

Adding an automated pull request comment can be useful in situations where you need to view or verify CI build changes further before merging to master/main. In this post, I'm going to show how you can add a comment to an Azure Repos pull request, with a link to download the latest build artifact.

I was recently tasked with providing a solution for Azure DevOps pull requests to have a comment added to them after a CI build, with a link to download the latest artifact for QA testing (a docker-compose.yml file in this case).

Enter Azure DevOps REST APIs!

After a bit of trial and error (ok, a lot of trial-and-error 😁), this is what I produced:

📄
For the below to work, you'll need to go into your repo's security settings and give the $ProjectName Build Service Allow permissions to Contribute to pull requests

Here is the result:

IMAGE

One thing that I really like about these tasks - they use a lot of predefined variables so are very generic, and they can be used as templates for other definitions if you have them!

The Azure DevOps REST API Reference documentation is a useful bookmark if you want to explore them further.