azure devops - Separate pipeline for each branch - Stack Overflow

admin2025-05-01  0

I create simple Azure DevOps Pipelines which should start for those specific branches:

trigger:
  branches:
    include:
      - main
      - develop
      - release

pool:
  name: $(agent)

# Rest of the code

I pushed that pipeline from develop branch and it starts executing. When I switched to the hotfix/test branch, and pushed the commit again, no pipeline was triggered. So I add above pipeline to hotfix/test again, now it works. The same with release I did, so now I have the same pipeline in three different branches. At the end I want to push my changes to main branch, and my assumption was that it will be working for all above branches and commits respectively.

In Pipeline settings I have set develop as default branch:

I am not sure if it is a default Azure DevOps Pipelines behavior or mine misunderstanding. However I want to have that pipeline in main branch and see that it works for commits pushed from those branches.

I create simple Azure DevOps Pipelines which should start for those specific branches:

trigger:
  branches:
    include:
      - main
      - develop
      - release

pool:
  name: $(agent)

# Rest of the code

I pushed that pipeline from develop branch and it starts executing. When I switched to the hotfix/test branch, and pushed the commit again, no pipeline was triggered. So I add above pipeline to hotfix/test again, now it works. The same with release I did, so now I have the same pipeline in three different branches. At the end I want to push my changes to main branch, and my assumption was that it will be working for all above branches and commits respectively.

In Pipeline settings I have set develop as default branch:

I am not sure if it is a default Azure DevOps Pipelines behavior or mine misunderstanding. However I want to have that pipeline in main branch and see that it works for commits pushed from those branches.

Share Improve this question edited Feb 1 at 20:28 scrapkowe asked Jan 2 at 15:15 scrapkowescrapkowe 1376 bronze badges 8
  • YAML pipeline file must exist in the branches specified in the trigger. – Rui Jarimba Commented Jan 2 at 15:26
  • Rui, you are everywhere when it comes about the Azure Pipeline topics :) thats good, thank you. Coming back to that question, it is weird MS approach, dont you think? It means that we need to maintain X files for each branches. – scrapkowe Commented Jan 2 at 17:09
  • Now I get lost myself, but how to add that pipeline dynamically to branch where we do not know the full branch name like for hotfix until it is created. Now it is hotfix/test, but tomorrow it might be hotfix/test2, so is there any solution to solve such situations? – scrapkowe Commented Jan 2 at 18:39
  • I don't think it's weird, by the contrary - when you think about it it makes sense. YAML pipelines and corresponding templates are files stored in a repository, so if you want to run the pipeline using branch XXX you must have them in that branch. – Rui Jarimba Commented Jan 2 at 19:52
  • hotfix/test and hotfix/test2 match the expression hotfix/* so you have nothing to worry about, as long as the YAML pipeline and corresponding template(s) are stored in the hotfix/xxxxxx branches. – Rui Jarimba Commented Jan 2 at 19:55
 |  Show 3 more comments

1 Answer 1

Reset to default 0

As mentioned in the comments, YAML pipeline file (and correspondent templates) must exist in the branches specified in the trigger.

I suggest you do the following when adding a new YAML pipeline:

  1. Create a dedicated branch for the pipeline
  2. Add pipeline and templates, containing the trigger configuration for the other branches such as dev, releases/*, hotfix/*, etc
  3. After testing the pipeline (and the trigger) create a pull request and merge it into the default branch (main or master)
  4. For new branches create them based on the default branch (which already contains the YAML pipeline files)
  5. For existing branches (e.g. dev) cherry-pick changes from the pull request containing the pipeline
转载请注明原文地址:http://anycun.com/QandA/1746110723a91815.html