首页 > 解决方案 > Tags trigger not working in azure pipelines

问题描述

I have the exact same pipeline in two different branches of the same repository, stage and prod.

I'd like the pipeline on branch stage to run when a tag starting with stage@ is created (e.g. stage@1.0.1); similarly, I'd like the pipeline on branch prod to run when a tag starting with prod@ is created (e.g. prod@1.0.1).

In branch stage, trigger is defined like this:

# .azure-pipelines.yml [refs/branches/stage]

trigger:
  tags:
    include:
      - stage@*

In branch prod, trigger is defined like this:

# .azure-pipelines.yml [refs/branches/prod]

trigger:
  tags:
    include:
      - prod@*

Now I created a pipeline on Azure DevOps named [Deploy to STAGE] from the file in the stage branch, and one named [Deploy to PROD] from the file in the prod branch.

I tried creating a tag:

$ git branch
  master
  prod
* stage

$ git tag -a stage@1.0.6 -m "stage@1.0.6"
$ git push --tags

I expected the [Deploy to STAGE] pipeline to start, but both pipelines started instead:

enter image description here

Am I missing something? Isn't the trigger supposed to only include tags matching the defined pattern? How do I correct the trigger to achieve the described flow?

标签: gitazureazure-devopsazure-pipelines

解决方案


The two pipelines Deploy to STAGE and Deploy to Prod are two identical pipelines. Though you choose the file from branch Prod when creating pipeline Deploy to Prod, this pipeline will apply to Stage branch too. This is because both the pipelines use the same azure-pipelines.yml file and this file exists on both stage and prod branch.

From the screenshot of the build runs, You can see the two pipelines were building the exact same stage tag. If you add a tag to prod branch, you will see both the pipeline will be triggered too.

Actually you only need to create either one of the two pipelines. Both of they will apply to prod and stage branch. So you can just delete pipeline Deploy to Prod. When you push a tag to prod branch. You will notice the pipeline Deploy to STAGE is building the prod tag.

If you have to create two pipelines. You need to rename the azure-pipelines.yml file in prod branch or create a new yml file with the some contents and with a different name. And create pipeline Deploy to PROD from this new yml file.

If you choose to create a new yml file to create pipeline Deploy to PROD, you need to disable the trigger (trigger: none) in the original azure-pipelines.yml file in prod branch, so that pipeline Deploy to Stage will not be triggered to build prod tag when tag is pushed to prod branch.

In summary, if you want to create different pipelines for different branches, you will have to create different pipeline yml files.


推荐阅读