Azure DevOps 仅触发特定 PR 的拉取请求

Azure DevOps trigger pull request for only specific PR's

用例:
我有一个 GitHub 存储库,它由基于区域的多个业务部门共享。每个区域业务部门都有自己的 ADO 管道,在他们自己的 ADO 项目上创建,但都共享同一个存储库。

问题:
这两个 ADO 项目都使用相同的存储库,Team-A 提出的 PR 需要触发 Project-A ADO 管道,目前它也会触发 Team-B ADO 管道。需要解决。

解法:
我们只需要为特定于每个区域业务部门的特定拉取请求触发 ADO 管道。

对于管道触发器,您可以使用 Path filters 将其限制为每个区域配置的 sub-folders。

Several branch policies offer path filters. If a path filter is set, the policy applies only to files that match the path filter. Leaving this field blank means that the policy applies to all files in the branch.

You can specify absolute paths and wildcards. Examples:

  • /WebApp/Models/Data.cs
  • /WebApp/*
  • *.cs

You can specify multiple paths using ; as a separator. Example:

  • /WebApp/Models/Data.cs;ClientApp/Models/Data.cs

Paths prefixed with ! are excluded if they would otherwise be included. Example:

  • /WebApp/;!/WebApp/Tests/ includes all files in /WebApp except files in /WebApp/Tests
  • !/WebApp/Tests/* specifies no files, since nothing is included first

The order of filters is significant. Filters are applied left-to-right.

对于 yaml 管道,您可以使用 paths include/exclude 将其限制为每个区域配置的 sub-folders。

trigger:
  batch: true
  branches:
    include:
    - features/*
    exclude:
    - features/experimental/*
  paths:
    exclude:
    - README.md

对于经典设计器管道,您可以使用 Path filters 将其限制为每个区域配置的 sub-folders。

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