嘿,我正在为逻辑应用程序进行 CI/CD 部署,我有一个表存储用于存储一些数据,我有两个表存储用于 test 和 prod 环境。我在 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')]) ': 预期的标记 'Identifier' 和实际的 'LeftSquareBracket'。".'.
我尝试用反斜杠转义引号,例如:encodeURIComponent(\'[parameters('table_storage_name')]\')
或 encodeURIComponent('[parameters(''table_storage_name'')]')
,但它们都引发错误。如何在 ARM 模板中引用 encodeURIComponent 中的参数?
答案 0 :(得分:0)
正如评论中所讨论的。学分:@marone
"path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"
答案 1 :(得分:0)
通过此链接找到解决方案 https://platform.deloitte.com.au/articles/preparing-azure-logic-apps-for-cicd
但这里是引用参数逻辑应用的步骤:
{
"$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": [
{
......
}
.......
"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')]"
}
}
}
}
]
}
"path": "/Tables/@{encodeURIComponent(parameters('table_storage_name'))}/entities"