【问题标题】:Unable to parse template language expression 'encodeURIComponent([parameters('table_storage_name')])'无法解析模板语言表达式'encodeURIComponent([parameters('table_storage_name')])'
【发布时间】:2021-04-29 10:01:14
【问题描述】:

嘿,我正在为一个逻辑应用程序进行 CI/CD 部署,我有一个表存储来存储一些数据,我有两个表存储用于 testprod 环境。我在 ARM 模板中创建了一个名为 *table_storage_name 的参数:

"parameters": {
// ....
"connections_azuretables_1_externalid": {
   "defaultValue": "/subscriptions/e5..../resourceGroups/myrg.../providers/Microsoft.Web/connections/azuretables-1",
      "type": "String"
        },
"table_storage_name": {
          "defaultValue": "testdevops",
          "type": "String"
        }
}

当我在 template.json 文件中引用参数时出现错误:

// ...
"Insert_Entity": {
  "runAfter": {
      "Initialize_variable": [
          "Succeeded"
      ]
  },
  "type": "ApiConnection",
  "inputs": {
      "body": {
          "PartitionKey": "@body('Parse_JSON')?['name']",
          "RowKey": "@body('Parse_JSON')?['last']"
      },
      "host": {
          "connection": {
              "name": "@parameters('$connections')['azuretables_1']['connectionId']"
          }
      },
      "method": "post",
      // problem occur after this line
      "path": "/Tables/@{encodeURIComponent('[parameters('table_storage_name')]')}/entities"
  }
}

但得到这个错误:

InvalidTemplate:模板验证失败:“第 1 行和第 582 列的模板操作 'Insert_Entity' 无效:“无法解析模板语言表达式 'encodeURIComponent([parameters('table_storage_name')]) ':预期的令牌'标识符'和实际的'LeftSquareBracket'。"。'。

我尝试使用反斜杠转义引号,例如:encodeURIComponent(\'[parameters('table_storage_name')]\')encodeURIComponent('[parameters(''table_storage_name'')]'),但它们都会引发错误。如何在 ARM 模板中引用 encodeURIComponent 中的参数?

【问题讨论】:

  • 你能在你展示的两行周围显示更多来自 ARM 模板的上下文吗?
  • 完成@silent :)
  • 看我的回答:)

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


【解决方案1】:

如 cmets 中所述。学分:@marone

 "path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"

【讨论】:

  • 感谢您的评论,它正在工作,但我们遇到了一个新错误 :) "Unable to parse template language expression 'encodeURIComponent(testdevopsprod)': expected token 'LeftParenthesis' and actual 'RightParenthesis'.".' 它必须是 encodeURIComponent('testdevopsprod') 带引号我猜不是?
  • 我从 here 尝试了这个 "/Tables/@{encodeURIComponent(encodeURIComponent(parameters('table_storage_name')))}/entities",但在插入实体时逻辑应用程序出错:Unable to process template language expressions in action 'Insert_Entity' inputs at line '1' and column '1962': 'The workflow parameter 'table_storage_name' is not found.' 我在 prod 中部署后检查了参数文件,但是没有找到 table_storage_name 参数和我创建的 template.json
  • 这个工作"path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"
  • @marone 感谢您的分享,您可以发布您的答案并将其标记为已接受的答案,这将有助于遇到相同问题的其他社区成员,我们可以将此主题存档,谢谢。
  • @marOne 我改变了我的答案。随意发布你自己的,我会删除我的或接受我的回答。
【解决方案2】:

从此链接https://platform.deloitte.com.au/articles/preparing-azure-logic-apps-for-cicd找到解决方案

但这里是引用参数逻辑应用程序的步骤:

  1. 在 template.json 中创建一个 ARM 参数 table_storage_name_armparam,以便使用它的值来引用 ARM 参数的值(是的,这很令人困惑,但你会理解的):
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "table_storage_name_armparam": {
          "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
         ......
}
  1. 现在在逻辑应用参数值(在 json 文件底部)中创建逻辑应用参数 table_storage_name,该参数的值将是第 1 步中创建的 ARM 参数:
.......
"parameters": {
                    "$connections": {
                        "value": {
                            "azuretables": {
                                "connectionId": "[parameters('connections_azuretables_externalid')]",
                                "connectionName": "azuretables",
                                "id": "/subscriptions/xxxxx-xxxx-xxxx-xxxxxxxx/providers/Microsoft.Web/locations/francecentral/managedApis/azuretables"
                            }
                        }
                    },
                    "table_storage_name": {
                      "value": "[parameters('table_storage_name_armparam')]"
                    }
                }
            }
        }
    ]
}
  1. 最后,引用逻辑应用参数值如下:
"path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"

【讨论】:

  • 您好,感谢您的分享,您可以Accept it as an Answer,它可以帮助遇到相同问题的其他社区成员,我们可以归档这个帖子,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-19
  • 2012-05-24
  • 2016-06-27
相关资源
最近更新 更多