Azure DevOps - Use YAML templates in a Git Submodule

我的梦境 提交于 2021-01-28 07:03:35

问题


So i have 11 repositories of 1 project, they are all micro-services.
I have one repository called DevOps where everything that has to be shared across YAML builds, is shared using a Git Submodule.
For some reason i cant seem to reference yaml templates that are in a git module.

Options:


When i try to run a build by trigger or manually i get the error:

File /DevOps/A/Templates/A-test-template.yml not found in repository http://A.azuredevops.local/DefaultCollection/A/_git/A branch refs/heads/master version db2884cc2d188b8e281f78e8b27e4fd74ce77d58.,Unexpected step type: 'StepsTemplateReference'

YAML:

steps:

# Run Unit Tests
- template: DevOps/A/Templates/A-test-template.yml



SOLUTION:

Using a YAML:

resources:
  repositories:
    - repository: RepositoryAlias
      type: git
      name: "ProjectName/RepositoryName"

steps:
- template: DevOps/A/Templates/A-test-template.yml@RepositoryAlias

回答1:


I think this wont work, because steps have to be calculated before build actually starts and submodules are being checked out after the build starts. But, honestly, you should just use a proper way of doing it (not submodules):

# Repo: Contoso/LinuxProduct
# File: azure-pipelines.yml
resources:
  repositories:
    - repository: templates
      type: github
      name: Contoso/BuildTemplates

jobs:
- template: common.yml@templates  # Template reference

So just put them in a separate repo and reference the repo.

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



来源:https://stackoverflow.com/questions/57613676/azure-devops-use-yaml-templates-in-a-git-submodule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!