23

Working with Azure devops, and piplines yaml files. There is a trigger on the develop branch. However, when I am saving changes to the yaml file, it triggers a new build.

This happens cause the change to the yaml file is a new commit, captured by the trigger.

So my question is, how can I exclude changes to the yaml file, from triggering a new build?

Holy semicolon
  • 868
  • 1
  • 11
  • 27
sirpadk
  • 809
  • 2
  • 7
  • 12

2 Answers2

22

You can specify file paths to include or exclude. Note that the wildcard syntax is different between branches/tags and file paths.

# specific path build
trigger:
  branches:
    include:
    - master
    - releases/*
  paths:
    include:
    - docs/*
    exclude:
    - docs/README.md

Source: Build Azure Repos Git or TFS Git repositories - CI triggers - Paths

EDIT April 2021:

Wild cards are not supported with path filters.

Taken from that same source now:

You can specify file paths to include or exclude.

# specific path build
trigger:
 branches:
   include:
   - master
   - releases/*
 paths:
   include:
   - docs
   exclude:
   - docs/README.md

When you specify paths, you must explicitly specify branches to trigger on. You can't trigger a pipeline with only a path filter; you must also have a branch filter, and the changed files that match the path filter must be from a branch that matches the branch filter.

Tips:

  • Wild cards are not supported with path filters.
  • Paths are always specified relative to the root of the repository.
  • If you don't set path filters, then the root folder of the repo is implicitly included by default.
  • If you exclude a path, you cannot also include it unless you qualify it to a deeper folder. For example if you exclude /tools then you could include /tools/trigger-runs-on-these
  • The order of path filters doesn't matter.
  • Paths in Git are case-sensitive. Be sure to use the same case as the real folders.
  • You cannot use variables in paths, as variables are evaluated at runtime (after the trigger has fired).
rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • 2
    Wildcards aren't supported for trigger paths -- only full filenames or directory names. I tried using *.json for trigger in an Angular build and it was just ignored. – yzorg Apr 01 '21 at 18:40
  • Does this work if you also use `trigger: none`, which is used when you want to have the pipeline run based on a PR policy check in ADO only. – greg Dec 22 '21 at 05:42
  • @greg - for pull request, you need to go to the branch policies and set the path filter there. See more info here - https://learn.microsoft.com/en-us/azure/devops/repos/git/branch-policies?view=azure-devops&tabs=browser#path-filters – Varun Sharma Jan 11 '22 at 21:42
  • 4
    Wild cards for path filters are supported since September 8, 2021. See release notes: https://learn.microsoft.com/en-us/azure/devops/release-notes/2021/sprint-192-update#support-for-wild-cards-in-path-filters – corentinaltepe Apr 07 '22 at 09:18
19

With changes announced here Support for wild cards in path filters we can now use wild cards:

Wild cards can be used when specifying inclusion and exclusion branches for CI or PR triggers in a pipeline YAML file. However, they cannot be used when specifying path filters. For instance, you cannot include all paths that match src/app/**/myapp*. This has been pointed out as an inconvenience by several customers. This update fills this gap. Now, you can use wild card characters (**, *, or ?) when specifying path filters.

So you can now:

# specific path build
trigger:
  branches:
    include:
    - master
    - releases/*
  paths:
    include:
    - '*'
    exclude:
    - '**/*.yml'
    - '**/*.yaml'
boflynn
  • 3,534
  • 1
  • 27
  • 28
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
  • Thanks, I was specifically looking for YAML files. – Varun Sharma Jan 11 '22 at 19:00
  • 4
    Fair warning: the `**` path string is buggy and only matches nested directories. for example excluding `**/*.md` will exclude `.md` files in nested directories (e.g. `web/README.md`, but **does not** match `.md` files in the root directory (e.g. `README.md`) – Jthorpe Mar 16 '22 at 18:53