标签触发在天蓝色管道中不起作用 [英] Tags trigger not working in azure pipelines

查看:59
本文介绍了标签触发在天蓝色管道中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在同一个存储库的两个不同分支( stage prod )中具有完全相同的管道.

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

我希望分支 stage 上的管道在创建以 stage @ 开头的标签时运行(例如, stage@1.0.1 >);同样,我希望分支 prod 上的管道在创建以 prod @ 开头的标签时运行(例如, prod@1.0.1 ).

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).

在分支 stage 中,触发器的定义如下:

In branch stage, trigger is defined like this:

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

trigger:
  tags:
    include:
      - stage@*

在分支 prod 中,触发器的定义如下:

In branch prod, trigger is defined like this:

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

trigger:
  tags:
    include:
      - prod@*

现在,我从 stage 分支中的文件在Azure DevOps上创建了一个名为 [Deploy to STAGE] 的管道,以及一个名为 [Deploy to PROD]的管道.来自 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.

我尝试创建标签:

$ git branch
  master
  prod
* stage

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

我希望 [Deploy to STAGE] 管道启动,但是两个管道都启动了:

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?

推荐答案

Deploy to STAGE Deploy to Prod 这两个管道是两个相同的管道.尽管您在创建管道 Deploy to Prod 时从分支 Prod 中选择文件,但该管道也将应用于 Stage 分支.这是因为两个管道都使用相同的azure-pipelines.yml文件,并且该文件同时存在于stage和prod分支上.

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.

从构建运行的屏幕截图中,您可以看到两个管道正在构建完全相同的阶段标签.如果将标签添加到 prod 分支,您将看到两个管道也将被触发.

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.

实际上,您只需要创建两个管道之一.它们都将应用于prod和stage分支.因此,您只需删除管道 Deploy to Prod .当您将标签推入prod分支时.您会注意到管道 Deploy to STAGE 正在构建prod标签.

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.

如果必须创建两个管道.您需要在 prod 分支中重命名azure-pipelines.yml文件,或使用一些内容和不同的名称创建一个新的yml文件.然后从这个新的yml文件创建管道 Deploy to PROD .

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.

如果您选择创建一个新的yml文件来创建管道 Deploy to PROD ,则需要在原始的Azure管道中禁用触发器( trigger:none ).yml文件位于prod分支中,因此在将标签推送到prod分支时,不会触发管道 Deploy to Stage 来构建prod标签.

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.

总而言之,如果要为不同的分支创建不同的管道,则必须创建不同的管道yml文件.

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

这篇关于标签触发在天蓝色管道中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆