不同存储库上的 Azure Devops YAML 管道触发器
Azure Devops YAML Pipeline Trigger on different repositories
是否可以在 commits/PRs 上针对不同存储库(例如 Repo A)的分支到 azure-pipelines.yaml 文件所在的分支(例如 Repo B)设置 yaml 管道触发器?
我知道我可以针对 Repo B 构建管道并使用例如
来检查 Repo A
resources:
repositories:
- repository: Repo A
type: github
endpoint: ***
name: ***/RepoA
trigger:
- master
但是触发器只适用于 Repo B,即当我在 master 上提交到 Repo A 时,管道不会触发。
“Sprint 173”版本似乎包括 multi-repo triggers feature。我怀疑您可能遗漏了参考文献。
Here is an example that shows how to define multiple repository
resources in a pipeline and how to configure triggers on all of them.
trigger:
- main
resources:
repositories:
- repository: tools
type: git
name: MyProject/tools
ref: main
trigger:
branches:
include:
- main
- release
The pipeline in this example will be triggered if there are any
updates to:
main
branch in the self
repo containing the YAML file
main
or release
branches in tools repo
不幸的是 Multi-repo 触发器还支持 Git 集线器回购资源。
正如文档中所说:
Repository resource triggers only work for Azure Repos Git repositories at present. They do not work for GitHub or Bitbucket repository resources.
如果您使用的是 Azure Repos Git 存储库。您需要为存储库资源指定 trigger 部分以启用 Multi-repo 触发器。有关详细信息,请参阅文档 here。
由于您使用的是 github,因此您可以使用 pipeline completion triggers 作为解决方法。您可以参考以下步骤为 RepoB 管道设置管道完成触发器。
1,为 RepoA 设置触发管道。
您可以在 azure devops 中为 github RepoA 创建管道。推荐使用经典 UI 管道,因为它不会在您的 RepoA 中添加 azure-pipelines.yaml 文件。
我建议您在触发管道中添加一个空代理作业(没有任何任务)。这样管道运行将永远成功。
您需要为此触发管道启用持续集成。这样 RepoA 中分支的 commits/PRs 将自动触发此管道。
在管道 Edit 页面,转到 Triggers 选项卡,选中 Enable continuous integration
,添加要启用的分支CI 在分支过滤器部分
2、在触发管道中设置管道资源(即azure-pipelines.yaml 文件用于RepoB)
添加 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管道中的管道资源。您可以使用 Multi-repo 触发器实现相同的效果。
是否可以在 commits/PRs 上针对不同存储库(例如 Repo A)的分支到 azure-pipelines.yaml 文件所在的分支(例如 Repo B)设置 yaml 管道触发器?
我知道我可以针对 Repo B 构建管道并使用例如
来检查 Repo Aresources:
repositories:
- repository: Repo A
type: github
endpoint: ***
name: ***/RepoA
trigger:
- master
但是触发器只适用于 Repo B,即当我在 master 上提交到 Repo A 时,管道不会触发。
“Sprint 173”版本似乎包括 multi-repo triggers feature。我怀疑您可能遗漏了参考文献。
Here is an example that shows how to define multiple repository resources in a pipeline and how to configure triggers on all of them.
trigger: - main resources: repositories: - repository: tools type: git name: MyProject/tools ref: main trigger: branches: include: - main - release
The pipeline in this example will be triggered if there are any updates to:
main
branch in theself
repo containing the YAML filemain
orrelease
branches in tools repo
不幸的是 Multi-repo 触发器还支持 Git 集线器回购资源。
正如文档中所说:
Repository resource triggers only work for Azure Repos Git repositories at present. They do not work for GitHub or Bitbucket repository resources.
如果您使用的是 Azure Repos Git 存储库。您需要为存储库资源指定 trigger 部分以启用 Multi-repo 触发器。有关详细信息,请参阅文档 here。
由于您使用的是 github,因此您可以使用 pipeline completion triggers 作为解决方法。您可以参考以下步骤为 RepoB 管道设置管道完成触发器。
1,为 RepoA 设置触发管道。
您可以在 azure devops 中为 github RepoA 创建管道。推荐使用经典 UI 管道,因为它不会在您的 RepoA 中添加 azure-pipelines.yaml 文件。
我建议您在触发管道中添加一个空代理作业(没有任何任务)。这样管道运行将永远成功。
您需要为此触发管道启用持续集成。这样 RepoA 中分支的 commits/PRs 将自动触发此管道。
在管道 Edit 页面,转到 Triggers 选项卡,选中 Enable continuous integration
,添加要启用的分支CI 在分支过滤器部分
2、在触发管道中设置管道资源(即azure-pipelines.yaml 文件用于RepoB)
添加 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管道中的管道资源。您可以使用 Multi-repo 触发器实现相同的效果。