【问题标题】:Using templates that themselves use templates located in other repositories使用本身使用位于其他存储库中的模板的模板
【发布时间】:2021-10-12 23:37:23
【问题描述】:

我正在尝试使用来自多个存储库的多个作业/步骤模板。我的 YAML 管道中有以下依赖项:

pipeline.yaml@RepoA -> template1.yaml@RepoB -> template2.yaml@RepoC

Azure DevOps 似乎只支持仅一级深度的引用模板。

这是我正在使用的示例代码:

# pipeline.yaml@RepoA

resources:
  repositories:
    - repository: RepoB
      type: Git
      name: RepoB

extends:
  template: Build/YAML/Jobs/test-sdk.yaml@RepoB
# Build/YAML/Jobs/test-sdk.yaml@RepoB

resources:
  repositories:
    - repository: RepoC
      type: Git
      name: RepoC

jobs:
- job: AnotherJob

  steps:
  - template: Common/Steps/Initialize/ShowPackageVariables_01.yaml@RepoC

上述代码示例在解析模板时抛出错误:

/Build/YAML/Jobs/test-sdk.yaml@RepoB(第 23 行,第 15 列):其他存储库中的模板在引用另一个模板时可能不会指定存储库源。不允许使用模板引用“Common/Steps/Initialize/ShowPackageVariables_01.yaml@RepoC”。

任何如何解决此问题的想法将不胜感激。

【问题讨论】:

  • 我们设置了一个单独的 repo BuildTemplates,其中存储了多个 repos 中使用的所有模板。到目前为止,我没有尝试在那里使用引用其他模板的模板,但这应该更容易。 (哪些存储库在管道的构建选项卡中被命名为源?所有引用的存储库都需要在此处提及 - 并且可能缺少传递引用。)

标签: azure-devops azure-pipelines-yaml


【解决方案1】:

official documentation of repository resourcesusage of other repositories with templates 没有提到这是可能的。错误消息非常明确地指出,模板中的 repo 引用被禁止,这些模板本身位于与管道不同的 repo 中 - 唯一的例外是为此目的明确设计的 @self 引用。

目前无法绕过该限制。 YAML 管道在它们开始执行之前被完全解析,模板引用在解析管道时被解析并且解析器声明它不支持你描述的情况。

这适用于 Azure DevOps Services 和 Azure DevOps Server 2020。

VS 开发者社区有a request(最初发布on GitHub)以错误消息的第一句为标题。它被标记为已完成,但从 cmets 看来,假设的分辨率是“扩展”功能,但事实并非如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-10
    • 2019-12-27
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2020-06-04
    相关资源
    最近更新 更多