主控的 Azure DevOps CI 管道由分支的变化触发,反之亦然

Azure DevOps CI pipeline for master being triggered by changes in branch and vice versa

我有一个 CI 的回购构建触发器设置如下:

trigger:
- master

我有同一个仓库的一个分支,我想拥有它自己的管道。

在 pipeline.yml 的分支中,我有:

trigger:
- ops-workshop/ms-lab01

但是,如果我将更改提交到我的分支,则会触发主管道和分支管道的构建。

提交到 master 也会触发分支的管道(它不应该)。

我试过用branches节点排除master,但好像没有任何效果。参见:

trigger:
  branches:
    include:
    - ops-workshop/ms-lab01
    exclude:
    - master

似乎唯一可以阻止针对主管道触发构建的是,如果我使用通配符运算符排除所有内容 - 然后不会触发任何构建。

如果有影响,我将在 Azure DevOps 门户中进行这些更改。

这似乎是一件非常微不足道的事情,但我不明白为什么我会为同一个提交触发两个管道,即使设置了排除项也是如此。

我的完整 YAML 文件如下所示:

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- ops-workshop/ms-lab01

pool:
  vmImage: 'ubuntu-latest'

variables:
  buildConfiguration: 'Release'

steps:
- script: dotnet build --configuration $(buildConfiguration)
  displayName: 'dotnet build $(buildConfiguration)'

如有任何建议,我们将不胜感激。

我看到2个suggestions/things你可以查一下

首先检查构建管道定义中默认设置了哪个分支,YAML -> GetSources -> (image)

其次是尝试在构建管道定义中设置触发分支,选择选项 "Triggers",覆盖 yaml,并在那里设置分支(查看图像)

Microsoft 对 official documentation:

进行了解释,这已经够令人困惑了

My build pipeline is using yaml file from branch2 even though I set it to use from branch1.

Pipelines are not associated with a branch. They are associated with the repositories they build, and with the location of the YAML file relative to the root of that repository. However, every time a pipeline runs, it uses the YAML file and the content from a specific branch. That branch is determined based on where the change is pushed to (in the case of CI builds), where the PR is targeted to (in the case of PR builds), or what you manually specify (in the case of manual runs). Each branch's YAML file independently determines whether the pipeline should be scheduled for that branch.

这意味着如果你在两个分支中使用同一个 yaml 文件,每个分支都有一个特定的过滤器,同一个管道将处理两个 yaml 文件(因此触发器几乎没有用)。

要解决此问题,请使用 Azure DevOps UI 覆盖触发器,或者在分支之间使用不同的文件名。