How do I set up different pipelines for each branch in Azure

半城伤御伤魂 提交于 2021-01-28 05:05:53

问题


I have a single project but with two "master" branches.

  • master
  • virt/master

Each of them would have their own azure-pipeline.yml specific for their branch.

The first pipeline in master has the trigger set up as

trigger:
  batch: true
  branches:
    include:
      - refs/heads/master

The second one is in the virt/master branch.

trigger:
  batch: true
  branches:
    include:
      - refs/heads/virt/master

Here's the repository that I am experimenting on https://dev.azure.com/trajano/experiments/_git/multi-branch

  • master build https://dev.azure.com/trajano/experiments/_build?definitionId=11
  • virt/master build https://dev.azure.com/trajano/experiments/_build?definitionId=12

The problem I am having is when I push a change to the virt/master branch both pipelines get executed

Am I missing something in my configuration? Or is this a bug on Azure Devops?

I also tried to exclude but to no avail.

trigger:
  batch: true
  branches:
    include:
      - refs/heads/master
    exclude:
      - refs/heads/virt/master

回答1:


To create different pipelines for different branches. You need to rename the azure-pipelines.yml file in virt/master branch or create a new yml file with the some contents and with a different name. And create pipeline multi-branch(virt) from this new yml file.

If both pipelines are created from the yaml file with the same name azure-pipeline.yml. And the azure-pipeline.yml file exists in both of the branches. Then they are identical pipelines(even though the azure-pipeline.yml file contents might be different).

You can see from above screen. Pipeline multi-branch and multi-branch(virt) were building the same virt/master branch(using the tasks in the azure-pipeline.yml of virt/master). If you push to master branch. You will see both pipelines will be triggered to build master branch(using the tasks in the azure-pipeline.yml of master). Pipeline multi-branch and multi-branch(virt) are one pipeline

See this thread for more information.




回答2:


If you want to have separate pipelines please create separate file definition for them. I think that your configuration is fine and the issue is that you share the same file as definition.

When I moved to separate file it works as expected:



来源:https://stackoverflow.com/questions/65211005/how-do-i-set-up-different-pipelines-for-each-branch-in-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!