Mariano Rivera
Mariano Rivera

Reputation: 51

Using templates that themselves use templates located in other repositories

I am trying to use several job/steps templates from multiple repositories. I have the following dependencies in my YAML pipeline:

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

It looks like Azure DevOps only supports referencing templates only one level deep.

This is the sample code I am using:

# 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

The above code sample throws an error while parsing the template:

/Build/YAML/Jobs/test-sdk.yaml@RepoB (Line: 23, Col: 15): Templates in other repositories may not specify a repository source when referencing another template. The template reference 'Common/Steps/Initialize/ShowPackageVariables_01.yaml@RepoC' is not allowed.

Any ideas how to solve this issue would be appreciated.

Upvotes: 5

Views: 1953

Answers (1)

Palec
Palec

Reputation: 13551

The official documentation of repository resources nor usage of other repositories with templates does not mention that this is possible. The error message is very explicit about repo references being forbidden in templates that are themselves in a different repo than the pipeline -- the only exception is the @self reference explicitly designed for this purpose.

There is no way around that limitation for now. YAML pipelines are completely parsed before they start executing, template references are resolved when parsing the pipeline and the parser states it does not support the case you've described.

This holds for both Azure DevOps Services and Azure DevOps Server 2020.

VS Developer Community has a request (originally posted on GitHub) titled with the first sentence of the error message. It is marked completed, but from the comments, it looks like the supposed resolution is the "extends" feature, which is not the case.

Upvotes: 1

Related Questions