逻辑应用:在 ARM 模板中传递动态订阅 ID 和资源组名称

时间:2021-02-06 16:22:32

标签: azure-devops azure-logic-apps arm-template

嘿,我尝试使用 Azure DevOps 部署我的第一个具有动态资源组名称和订阅 ID 的逻辑应用程序已经有几天了,我查看了几个链接,这些链接在我的 template.json 文件中执行类似操作:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "workflows_app_name": {
            "defaultValue": "myLogicApp",
            "type": "String"
        },
        "connections_azuretables_externalid": {
            "value": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/azuretables",
            "type": "String"
        }
....

也试过了:

 "connections_azuretables_externalid": {
            "defaultValue": "[concat('/subscriptions/', subscription().id, '/resourceGroups/', resourceGroup().name, '/providers/Microsoft.Web/connections/azuretables')]",
            "type": "String"
        }

这也试图在参数中传递资源组名称和订阅:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "workflows_app_name": {
            "defaultValue": "myLogicApp",
            "type": "String"
        },
        "connections_azuretables_externalid": {
            "defaultValue": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('ressourceGroupName'), '/providers/Microsoft.Web/connections/azuretables')]",
            "type": "String"
        },
        "subscriptionId": {
          "type": "String"
        },
        "ressourceGroupName": {
          "type": "String"
        },
.....
}

但得到类似的错误

<块引用>

属性 id '[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('ressourceGroupName'), '/providers/Microsoft.Web/connections/azuretables')]'在路径 'properties.parameters.$connections.value.azuretables.connectionId' 无效。期望以“/subscriptions/{subscriptionId}”或“/providers/{resourceProviderNamespace}/”开头的完全限定资源 ID

我知道我遗漏或误解了某些东西,但无法弄清楚!谢谢。

2 个答案:

答案 0 :(得分:1)

您可以像下面这样在 template.json 文件的属性部分添加 API 属性,然后在 DevOps 库中引用变量名称

"api": {
         "id": "[concat(subscription().id,'/providers/Microsoft.Web/locations/',variables('rgLocation'),'/managedApis/azureblob')]"
       }

在这种情况下,存储位置是 Blob,您可以将其自定义为您选择的存储

答案 1 :(得分:0)

<块引用>

逻辑应用:在 ARM 模板中传递动态订阅 ID 和资源组名称

您可以尝试添加 Azure Cli 任务以获取订阅并创建一个名为 subscriptionId 的管道变量:

  jobs:
  - job: GetSubscription
    steps:
    - checkout: none
    - task: AzureCLI@2
      inputs:
        azureSubscription: 'CTP.AssuranceDW-Non-Production'
        scriptType: 'ps'
        scriptLocation: 'inlineScript'
        inlineScript: |
          $id = convertfrom-json (az account list --query "[?isDefault].id | [0]")
          Write-Host $id
          echo "##vso[task.setvariable variable=subscriptionId]$id"
    - powershell: Write-Host $(subscriptionId)

然后,我们可以使用 overrideParameters 或 replacetokens 任务将此值传递给 ARM 模板。

请查看主题 How to pass an Azure pipeline variable to an ARM template used by AzureResourceManagerTemplateDeployment@3 task? 了解更多详情。