0
votes

Regarding the Insertion section of this documentation:

https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#insertion

Is it possible to reference a local template as an inserted step(s) in a remote template.

For example, I can't seem to get something like this to work:

# File: jobs/build.yml (remotetemplates)

parameters:
  preBuild: []
  preTest: []
  preSign: []

jobs:
- job: Build
  pool:
    vmImage: 'vs2017-win2016'
  steps:
  - script: cred-scan
  - ${{ parameters.preBuild }}
  - task: msbuild@1
  - ${{ parameters.preTest }}
  - task: vstest@2
  - ${{ parameters.preSign }}
  - script: sign

# File: .vsts.ci.yml

jobs:
- template: jobs/build.yml@remotetemplates
  parameters:
    preBuild:
    - template: templates/steps/my-local-steps.yml

The result is something like: jobs/build.yml@remotetemplates: File templates/steps/my-local-steps.yml not found in repository <URL of remote repository>

Is there another approach I can use that would allow me to do this?

1
Hi, how the things going now? Does the below explanation could solve your puzzle? If not, please leave comment with any puzzle to let us know.Merlin Liang
@MerlinLiang-MSFT - Yes, thank you for your help with this!poltj18

1 Answers

1
votes

Is it possible to reference a local template as an inserted step(s) in a remote template.

Need sorry to say that no, you can't.

When you call one yml file from another template repos, all the template file must come from one same repos. Because the logic of template repos called in another repos is making the template repository is completely independent, only stores templates and used by other repositories. The significance of this design is to improve the reuse rate of code, called templates. Another advantage is regulate the templates.

So, when you use the template repository in YAML, the templates can only come from this template repository.

Is there another approach I can use that would allow me to do this?

There has two method.

  • Store this templates/steps/my-local-steps.yml file in your template repository. Then, don't need add other code. Just simply script is ok.

If this, there are some errors on your .vsts.ci.yml file.

resources:
  repositories:
    - repository: templates
      type: git
      name: {projectname}/{repos name}
jobs:
  - template: jobs/build.yml@templates
    parameters:
      preBuild:
      - template: {local steps which store at your template repository}.yml

Refer to this doc for template reference format: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/templates?view=azure-devops#using-other-repositories

  • Convert this templates/steps/my-local-steps.yml into script, add the pure script into this insertion YAML.

Hope this could help you.