git - 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:
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?
解决方案
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.
推荐阅读
- javascript - 随机按钮生成器需要修复以避免加载同一页面
- android - Restore focus to input after configuration change
- python - Pandas 将列从 str 转换为 float
- java - Hashmap 不断返回空值
- hyperledger-fabric - Hyperledger Fabric 1.2.0 开发者链码教程无法获取和构建
- javascript - blueprintjs 中的 CSS 无法正确加载
- android - 如何在android的进程中访问相同的push id而不是创建一个新的
- r - 我正在做文本挖掘,如果我有一些文档的树状图,然后将其切割成一个级别我怎样才能获得该切割级别的所有术语?
- javascript - DataTable:如何在 HTML 中添加自定义按钮手册
- android - Gitlab-CI执行后不生成apk