Build validations for multiple pipelines on Azure Devops

One frequent scenario when working with legacy projects is having a single repository with all of our solutions and projects inside. All of our code live together and every developer has access to every project. That sounds a bit scary but if we enforce strong branch policies and code reviews it should work just fine.

Another problem that we need to solve is how to implement continuous integration on each project. Luckily, with Azure DevOps that looks pretty easy too: we can create multiple pipelines and trigger them by looking into the files that are been modified, so we can build each project independently only when we need to.

Where each pipeline would look something like this:

But here is the problem: when enforcing build validation in our Pull Requests by default only one pipeline will be triggered (the first created pipeline) even if the changes we are sending are not related to that pipeline. What we will see next is our pipeline in green meaning “build validation passed” but if we look inside the build never run. 

The solution is to set up “build validations” accordingly. Sadly, this is deep hidden within the Azure DevOps project’s settings: 

Project Settings / Repositories / <your Repo> / Policies Tab / Branch Policies Section / <Your Branch> / Build Validation Section

You will see this:

By clicking the add button you are prompted with a form to create a “Build Validation”, you will choose a pipeline, a path filter, and other settings that you will recognize. After creating the build validation you will then see it enabled:

On the path filter section, you can list several paths as you need to be separated by a semicolon. For excluded paths, you need to use an exclamation mark. You should create a build validation for each pipeline to be run accordingly. 

And that’s all, when sending pull requests the correspondent pipelines will be triggered as build validations. If your changes impact more than one project you may see more than one validation been executed, as it should be.

If you have any other solutions or any other approach to this problem, please feel free to share links in the comments section. Good luck!

*Documentation about this: https://docs.microsoft.com/en-us/azure/devops/repos/git/branch-policies