不同存储库上的Azure Devops YAML管道触发器

时间:2020-08-05 15:55:26

标签: azure-devops azure-devops-yaml

是否可能在不同存储库(例如Repo A)到azure-pipelines.yaml文件所在(例如Repo B)的分支的提交/ PR上使用yaml管道触发器?

我知道我可以针对Repo B建立管道,并使用以下代码将其签出Repo A:

resources:
  repositories:
  - repository: Repo A
    type: github
    endpoint: ***
    name: ***/RepoA

trigger:
 - master

但是触发器仅适用于仓库B,即当我对仓库A进行主提交时,管道不会触发。

2 个答案:

答案 0 :(得分:2)

最新版本似乎包含此feature.,我怀疑您可能会缺少参考。

这里是显示如何定义多个存储库的示例 管道中的资源,以及如何在所有资源上配置触发器。

trigger:
- main

resources:
  repositories:
  - repository: tools
    type: git
    name: MyProject/tools
    ref: main
    trigger:
      branches:
        include:
        - main
        - release

如果有 更新为:

    自我回购中包含YAML文件的
  • 主分支
  • 工具存储库中的main或release分支

答案 1 :(得分:0)

不幸的是,Github回购资源还支持多回购触发器。

如文档中所述:

存储库资源触发器当前仅适用于Azure Repos Git存储库。它们不适用于GitHub或Bitbucket存储库资源。

如果使用的是Azure Repos Git存储库。您需要为存储库资源指定 trigger 部分,以启用多重回购触发器。有关更多信息,请参见文档here

由于您使用的是github,因此可以使用 pipeline completion triggers 作为解决方法。您可以参考以下步骤为RepoB管道设置管道完成触发器。

1,为RepoA设置触发管道

您可以在azure devops中为github RepoA创建管道。建议使用经典UI管道,因为它不会在RepoA中添加azure-pipelines.yaml文件。

我建议您在触发管道中添加一个空的代理作业(不包含任何任务)。这样管道运行将始终成功。

enter image description here

您需要为此触发管道启用持续集成。这样,RepoA中分支的提交/ PR将自动触发该管道。

在管道的编辑页面中,转到触发器标签,选中Enable continuous integration,在“分支过滤器”部分中添加要启用CI的分支

enter image description here

2,在触发的管道中设置管道资源(即RepoB的azure-pipelines.yaml文件)

添加pipeline resources并在管道资源中指定触发器部分。参见以下示例:

resources:
  repositories:
  - repository: Repo A 
    type: github
    endpoint: ***
    name: ***/RepoA

  pipelines:
  - pipeline: repoAPipeline   # Name of the pipeline resource
    source: triggeringPipeline-RepoA # Name of the triggering pipeline
    trigger: 
      branches:
      - releases/*
      - master

对RepoA进行更改后,触发管道将被触发并成功完成。触发管道完成后,将触发RepoB管道。

通过建立RepoA的触发管道和RepoB管道中的管道资源。使用多回购触发器可以达到相同的效果。