Triggering Azure DevOps builds based on changes to sub folders
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Triggering an Azure DevOps pipeline only when certain folders change is a common monorepo optimization. Instead of rebuilding everything for every commit, you can use path filters so a pipeline runs only when relevant subdirectories were modified.
The important detail is that these filters belong in the pipeline trigger configuration itself. If the trigger does not match, the pipeline does not start at all.
Use YAML path filters on the trigger
In a YAML pipeline, configure branch filters and path filters together:
This means:
- pushes to
maincan trigger the pipeline - only changes under
src/ServiceAorsrc/Sharedmatter - documentation changes under
src/ServiceA/docsdo not trigger the build - pull requests targeting
mainfollow the same folder logic
That is the standard pattern for folder-based triggering.
Create separate pipelines for separate folders
In a monorepo, the cleanest design is often one pipeline per service or deployable unit. Each pipeline watches only the directories that affect that service.
For example:
- '
service-a-pipeline.ymlwatchessrc/ServiceA/*' - '
service-b-pipeline.ymlwatchessrc/ServiceB/*' - '
infra-pipeline.ymlwatchesinfra/*'
This keeps pipelines focused and prevents one service from triggering unrelated builds.
Include shared folders deliberately
One common oversight is forgetting shared code. If ServiceA depends on code in src/Shared, then the Service A pipeline should watch both folders.
Without that shared path, a change in common code may fail to trigger the pipeline that actually depends on it.
Configure pull request triggers too
Teams often configure push triggers carefully and then forget pull request triggers. If PR validation should also be folder-aware, define pr.paths explicitly.
That keeps PR validation aligned with the same subfolder boundaries as your continuous integration builds.
Keep repository structure predictable
Path-based triggers work best when the repository layout is stable and easy to understand. Folder triggers become fragile if directories are renamed often or if ownership boundaries are unclear.
A clean layout such as this is much easier to maintain:
- '
src/ServiceA/' - '
src/ServiceB/' - '
src/Shared/' - '
infra/'
The clearer the folder ownership model, the safer your path triggers become.
This also makes it easier for new team members to understand why a specific pipeline ran or did not run after a commit touching a particular directory.
Common Pitfalls
The most common mistake is putting folder checks inside pipeline steps instead of inside the trigger. That still starts the pipeline on every change and only skips work after startup.
Another issue is forgetting shared directories, which causes dependent services to miss builds when common code changes.
Teams also sometimes configure trigger but forget pr, which leads to precise push builds but overly broad pull request validation.
Finally, be careful with include and exclude patterns. An exclude rule that is too broad can silently prevent builds you expected to run.
Summary
- Use
trigger.pathsandpr.pathsin Azure DevOps YAML to react only to changes in relevant folders. - In monorepos, separate pipelines per service are often the cleanest approach.
- Include shared directories when multiple services depend on them.
- Configure PR path filters as well as push path filters.
- Keep folder ownership simple so the trigger rules stay trustworthy.
Related reading
- Two clusters on EKS, how to switch between them
- Unable to add GSI to DynamoDB table using CloudFormation
- unable to call firefox from selenium in python on AWS machine
- Unable to connect aws s3 bucket using boto
- Trying to start the kubernetes in Docker-Desktop but it's stuck
- Two conflicting long lived process managers
- Unable to connect to AWS EKS cluster
- Unable to create a stage in AWS API Gateway

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.