3
votes

I have a CI build trigger setup for a repo as follows:

trigger:
- master

I have a branch of the same repo that I would like to have it's own pipeline.

In the pipeline.yml for the branch I have:

trigger:
- ops-workshop/ms-lab01

However, if I commit changes to my branch, builds are triggered for both the master and branch pipelines.

Committing to master also triggers the pipeline for the branch (which it shouldn't).

I have tried using the branches node to exclude master but it doesn't seem to have any effect. See:

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

The only thing that seems to stop builds from being triggered against the master pipeline is if I use the wildcard operator to exclude everything - no builds are then triggered.

I am making these changes in the Azure DevOps portal if that makes a difference.

This seems to be something very trivial, but I don't understand why I'm getting two pipelines triggered for the same commit, even with exclusions set.

My full YAML file looks like this:

# 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)'

Any suggestions would be appreciated.

2

2 Answers

3
votes

I see 2 suggestions/things you can check.

First check which branch is set by default in build pipeline definition, YAML -> GetSources -> (image)

enter image description here

Second is to try set triggered branches in build pipeline definition, choose option "Triggers", override yaml, and set branches there (look at image)

enter image description here

2
votes

It's confusing enough that Microsoft put an explanation on the 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.

What that means is that if you use the same yaml file in two branches, each one with a specific filter, the same pipeline will process both yaml files (and therefore the trigger is pretty much useless).

To work around this, either override the triggers with the Azure DevOps UI, or use a different file name between branches.