azure-devopsyamlazure-pipelinesbuild-triggers

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


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://learn.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.


Solution

  • 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