简体   繁体   中英

How can I exclude changes to the pipeline yaml file to trigger a build i azure devops?

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?

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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM