azure-devops - 使用来自外部存储库的 ARM 模板
问题描述
我正在使用 azure 多级管道,在单独的存储库中使用带有模板的部署作业。我目前开始在我的部署过程中使用 ARM 模板,并且还想运行位于不同存储库中的 ARM 模板。这是我有点卡住的地方,任何帮助/建议表示赞赏。
为了说明我的设置:
- Repo A -> 必须构建并部署到 azure 的源代码
- Repo B -> Azure 管道模板(仅包含 yml 文件)
- 回购 C -> 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
解决方案
我也偶然发现了这个问题,不得不将另一个 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'
有关下载管道工件任务的更多信息,请查看以下链接: 下载管道工件任务
推荐阅读
- python - 从 Firebase 中的字典中提取单个数据(使用 Pyrebase 和 Flask)
- angular - “ShoppingCartComponent”类型上不存在属性“myForm”
- python - 如何将数据帧中的字节值转换为python中的常规整数
- r - 重命名 JSON 实体流
- r - 找到所有具有共同索引的数字 - R
- regex - htaccess 从 url 中删除段并重定向到 https 和 www
- python - 取熊猫中每一列的行均值(python)
- apache-spark - COSMOS DB write issue from Databricks Notebook
- c++ - 在 C++ 中初始化类的成员
- google-cloud-platform - 通过使用 gsutil 从另一个文件读取路径来访问一个存储桶中的文件