首页 > 解决方案 > 使用来自外部存储库的 ARM 模板

问题描述

我正在使用 azure 多级管道,在单独的存储库中使用带有模板的部署作业。我目前开始在我的部署过程中使用 ARM 模板,并且还想运行位于不同存储库中的 ARM 模板。这是我有点卡住的地方,任何帮助/建议表示赞赏。

为了说明我的设置:

所以我想要完成的是:A使用B使用C

REPO A:文档构建和发布 yml

resources:
  repositories:
    - repository: templates
      type: git
      name: <ACCOUNT>/Azure.Pipelines.Templates
      ref: refs/tags/2.2.40

stages:
  - stage: Build
    jobs:
      - template: src/jobs/doc-build.yml@templates

  - stage: DEV
    jobs:
      - template: src/deployment-jobs/doc.yml@templates
    ....

REPO B:文档部署

parameters:
  webAppName: ''
  connectedServiceName: 'DEV'

jobs:
  - deployment: doc_deploy
    pool:
      name: 'DOC'
    environment: 'doc'
    strategy:
      runOnce:
        deploy:
          steps:
            - template: ../deployment/arm-template.yml
              parameters:
                connectedServiceName: ${{ parameters.connectedServiceName }}
                resourceGroupName: 'documentation'
                templateFile: $(Build.SourcesDirectory)/Azure.ARM.Templates/src/web-app/documentation.jsonc
                paramFile: $(Build.SourcesDirectory)/Azure.ARM.Templates/src/web-app/documentation-params.json
                parameters: -name ${{ parameters.webAppName }}
            ...

REPO C:包含 arm 模板 + 参数文件

我面临的问题是我似乎无法访问 repo c 的文件。我尝试repository在多个级别上添加另一个条目,但它似乎根本没有克隆依赖仓库。

我目前的解决方法/解决方案:

使用 powershell 脚本手动克隆 repo C 并直接引用磁盘上的文件。

相关 github 问题:https ://github.com/microsoft/azure-pipelines-yaml/issues/103

标签: azure-devopsyamlazure-resource-managermultistage-pipeline

解决方案


我也偶然发现了这个问题,不得不将另一个 repo 中的 arm 模板加载到当前版本中。我所做的是在包含 arm-template 的 repo 上设置构建,生成具有以下 azure-pipelines.yml 的构建工件:(这将是您的 repo c)

trigger:
- master

steps:
- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(System.DefaultWorkingDirectory)/templates'
    ArtifactName: 'templates'
    publishLocation: 'Container'

之后我可以在实际管道中添加以下步骤:

- task: DownloadPipelineArtifact@2
            displayName: 'Get ARM Templates'
            inputs:
              buildType: 'specific'
              project: <YOUR-PROJECT-ID>'
              definition: '<ARM-BUILD-DEFINITION-ID>'
              buildVersionToDownload: 'latest'
              artifactName: 'scripts'
              targetPath: '$(Pipeline.Workspace)/templates'

我能够按如下方式访问文件:

- task: AzureResourceGroupDeployment@2
            displayName: 'Create Queues $(ResourceGroup.Name) '
            inputs:
              azureSubscription: '<YOUR-SUBSCRIPTION>'
              resourceGroupName: '$(ResourceGroup.Name)'
              location: '$(ResourceGroup.Location)'
              csmFile: '$(Pipeline.Workspace)/templates/servicebus.json'

有关下载管道工件任务的更多信息,请查看以下链接: 下载管道工件任务


推荐阅读