如何在 Azure ARM 模板中链接模板?

Kun*_*Waz 1 azure azure-devops azure-template

我有多个要链接的 ARM 模板。但是,当我使用时,"[uri(deployment().properties.templateLink.uri, 'transform.json')]"我收到一条错误消息,告诉我 deployment() 在本地或通过 Azure DevOps 管道运行时提供了一个不包含 templateLink 的对象。

因此,我尝试发送我在 Azure DevOps 中构建项目时创建的工件的路径"[concat(parameters('templateDirectory'), '/transform.json')]",然后在调用模板时将其作为参数提供。但是后来我得到了这个错误

At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
Details:
BadRequest: {
"error": {
    "code": "InvalidContentLink",
    "message": "The provided content link 'file:///D:/a/r1/a/_Infrastructure/ARM/shared/transform.json' is invalid or not supported. Content link must be an absolute URI not referencing local host or UNC path."
}
} undefined
Task failed while creating or updating the template deployment.
Run Code Online (Sandbox Code Playgroud)

所以我的问题是,当我通过 Azure DevOps 管道进行部署时,我应该如何处理模板的链接?

我是否必须在构建步骤中将其复制到存储中,以便我可以在部署步骤中使用 http 或 https 访问它,如果是这样,最好的方法是什么?似乎有点复杂。

解决方案更新

因此,我采用的解决方案是将所有模板文件上传到我创建的临时存储中,然后将其路径添加到引用所有模板的主模板中。

任务概述以更好地了解它是如何完成的: 在此处输入图片说明

将模板复制到 blob:

在此处输入图片说明

部署ARM模板:

在此处输入图片说明

这里是在引用其他模板的主模板中如何使用它的片段:

"resources": [
  {
    "apiVersion": "2015-01-01",
    "name": "dashboard-24h",
    "type": "Microsoft.Resources/deployments",
    "properties": {
      "mode": "Incremental",
      "templateLink": {
        "uri": "[concat(parameters('templateBasePath'), '/dashboard/24h/azuredeploy-dashboard-deploy.json')]",
        "contentVersion": "1.0.0.0"
      },
      "parameters": {
        "templateBasePath": {
          "value": "[parameters('templateBasePath')]"
        },
        "appName": {
          "value": "[parameters('appName')]"
        }
      }
    }
  },
  ...
]
Run Code Online (Sandbox Code Playgroud)

4c7*_*b41 7

因此,如果您想使用deployment().properties.templateLink.uri您的模板,则必须从 url 部署,而不是从本地磁盘部署。

嵌套模板总是必须从 url 部署。因此,如果您想使用上述方法,则所有内容都必须上传到可公开访问的某个地方(或者必须通过 URL 进行身份验证,例如 SAS 令牌)。

我通常做的 - 在部署之前运行一个简单的 powershell 脚本,将所有模板上传到一个公共位置,之后我只使用部署功能。