Multiple pipeline triggers, for single commit

83 views Asked by At

multiple pipeline triggered on a single commit

I have this yaml pipeline running on my hosted agent. My issue is when I commit the pipeline it triggers and runs multiple pipeline instead of only one pipeline. What changes I have to make so that the pipeline runs only once when I commit(trigger)

trigger:
  - main

pool:
  name: Default

steps:
  - task: PowerShell@2
    displayName: 'Create text files'
    inputs:
      targetType: 'inline'
      script: |
        Set-Content -Path $(Build.SourcesDirectory)/file1.txt -Value "Hello from file 1"
        Set-Content -Path $(Build.SourcesDirectory)/file2.txt -Value "Hello from file 2"
1

There are 1 answers

0
Kevin Lu-MSFT On

From your screenshot and YAML code, the cause of the issue is that all pipelines have set the same Pipeline trigger: trigger: main.

In this case, when you do the commit operation in the main branch, it will trigger all pipelines which have set the pipeline trigger to main branch.

To solve this issue, you can refer to the following two situation:

1.If all Pipelines are using Same YAML file, you need to navigate to YAML Editor -> Triggers.

enter image description here

You can enable the option: Override the YAML continuous integration trigger from here. Then you can disable the trigger for other pipelines and enable the trigger for target pipeline.

enter image description here

2.If all pipelines are using Different YAML file, you can edit the YAML Pipelines to set the trigger to none and only set one pipeline to be triggered by main branch.

For example:

trigger: none

Or you can set the path filter in the trigger to exclude the files to trigger the pipeline.

For example:

trigger:
  branches:
    include:
    - main
    - releases/*
  paths:
    include:
    - docs
    exclude:
    - docs/README.md

For more detailed info, you can refer to the doc: Disabling the CI trigger