【问题标题】:How to reuse yaml templates in different Azure DevOps team project?如何在不同的 Azure DevOps 团队项目中重用 yaml 模板?
【发布时间】:2019-07-24 09:49:40
【问题描述】:

我正在创建一个集成管道,该管道应该执行依赖项目的构建管道(作为验证构建)。所有这些项目都托管在他们自己的团队项目中的 Azure DevOps 中。为了调用各自的管道,我想到了使用repository 资源。

根据文档herehere,应该可以从不同的存储库执行 YAML 模板。这些示例展示了如何将 repository 资源用于 GitHub 托管的存储库,但不清楚如何连接到 Azure Repos 上托管的不同团队项目。当托管在同一个团队项目中时,可以按照this answer 中的说明完成。

我试过这个:

resources:
  repositories:
  - repository: MyRepoAlias
    type: git
    name: MyRepo
    ref: 'refs/heads/master'

    # Adding/omitting an endpoint doesn't matter
    endpoint: 'MyRepo Service Connection'

pool:
  vmImage: 'windows-2019'

steps:
  # Calling template on the reference repository
  - template: '.\Templates\RunBuild.yml@MyRepoAlias'

作为记录,参考存储库存在于同一个 AzD 组织中。我是否将“端点”属性添加到端点也没关系。在这种情况下,我使用基于令牌的身份验证和完全访问 PAT 将其链接到“Azure Repos/Team Foundation Server”类型的服务连接。

问题:

  • 有人知道如何从 YAML 中的不同团队项目中引用 Azure Repos 托管的 Git 存储库吗?
  • 在 AzD 中可能有一些替代方法将管道链接在一起?

【问题讨论】:

    标签: git azure-devops azure-pipelines


    【解决方案1】:

    管道支持两种类型的存储库,git 和 github。 git 是指 Azure Repos Git 存储库。如果您选择 git 作为您的类型,则 name 指的是同一项目中的另一个存储库。例如,其他回购。要引用同一组织内另一个项目中的存储库,请在名称前加上该项目的名称。例如,OtherProject/otherRepo。

    所以你需要这样做:

      - repository: MyRepoAlias
        type: git
        name: MyProject\MyRepo
        ref: 'refs/heads/master'
    

    你不需要端点,你不需要服务连接(如果它们在同一个 Azure DevOps 组织下)

    https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema#resources

    【讨论】:

    • 确实在文档中提到过,完全错过了那句话。感谢您指出。
    猜你喜欢
    • 1970-01-01
    • 2021-06-07
    • 2021-10-14
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 2021-03-12
    • 2023-03-04
    • 2015-10-09
    相关资源
    最近更新 更多