Azure devops 通过'将api管理策略传递给arm模板;Azure资源组部署&x27;任务
我正在Azure管道中使用“Azure资源组部署任务”部署API管理服务。我的一个参数是“策略内容”(xml内容像字符串一样传递) 我现在看到的是,此任务将转换此字符串:Azure devops 通过'将api管理策略传递给arm模板;Azure资源组部署&x27;任务,azure-devops,azure-resource-manager,azure-api-management,Azure Devops,Azure Resource Manager,Azure Api Management,我正在Azure管道中使用“Azure资源组部署任务”部署API管理服务。我的一个参数是“策略内容”(xml内容像字符串一样传递) 我现在看到的是,此任务将转换此字符串: "<policies> <inbound> <authentication-managed-identity resource="RESOURCE_URL_ID" output-token-variable-name="msi-access-token" ignore-er
"<policies>
<inbound>
<authentication-managed-identity resource="RESOURCE_URL_ID" output-token-variable-name="msi-access-token" ignore-error="false" />
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (string)context.Variables["msi-access-token"])</value>
</set-header>
<choose>
<when condition="@(context.Product != null)">
<set-header name="Header-Tenant-Id" exists-action="override">
<value>@(context.Product.Name)</value>
</set-header>
</when>
</choose>
</inbound>
<backend>
<forward-request/>
</backend>
<outbound>
</outbound>
<on-error>
</on-error>
</policies>"
”
@(“承载”+(字符串)上下文变量[“msi访问令牌”])
@(context.Product.Name)
"
为此:
"'<policies>\t<inbound>\t\t<authentication-managed-identity resource=\"api://09a361fe-cd46-4609-a112-86725e4b3338\" output-token-variable-name=\"msi-access-token\" ignore-error=\"false\" />\t\t<set-header name=\"Authorization\" exists-action=\"override\">\t\t\t<value>@(\"Bearer \" + (string)context.Variables[\"msi-access-token\"])</value>\t\t</set-header>\t\t<choose>\t\t\t<when condition=\"@(context.Product != null)\">\t\t\t\t<set-header name=\"Header-Tenant-Id\" exists-action=\"override\">\t\t\t\t\t<value>@(context.Product.Name)</value>\t\t\t\t</set-header>\t\t\t</when>\t\t</choose>\t</inbound>\t<backend>\t\t<forward-request />\t</backend>\t<outbound>\t</outbound>\t<on-error>\t\t<set-header name=\"ErrorMessage\" exists-action=\"override\">\t\t\t<value>@(context.LastError.Message)</value>\t\t</set-header>\t\t<set-header name=\"ErrorStatusCode\" exists-action=\"override\">\t\t\t<value>@(context.Response.StatusCode.ToString())</value>\t\t</set-header>\t</on-error></policies>'"
“'\t\t\t\t\t\t\t\t@(\'Bearer\'+(string)context.Variables[\'msi access token\')\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t@(context.LastError.Message)\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t(context.Product.Name\t\t\t\t
它在输入字符串的开头和结尾添加一个引号。
由于此行为,我出现以下错误:“根级别的数据无效。第1行,位置1。”,部署失败
我通过“覆盖模板参数”-apimPolicy“$(ApimServicePolicy)”
关于如何跳过这些单引号添加的任何想法?对于此问题,问题可能是
参数。Azure资源组部署任务无法解析xml
文件。Azure资源组部署任务仅支持解析json
格式的参数文件
您可以通过Google搜索许多将XML转换为JSON的工具,例如:
{
"policies": {
"inbound": {
"authentication-managed-identity": {
"_resource": "RESOURCE_URL_ID",
"_output-token-variable-name": "msi-access-token",
"_ignore-error": "false"
},
"set-header": {
"value": "@(\"Bearer \" + (string)context.Variables[\"msi-access-token\"])",
"_name": "Authorization",
"_exists-action": "override"
},
"choose": {
"when": {
"set-header": {
"value": "@(context.Product.Name)",
"_name": "Header-Tenant-Id",
"_exists-action": "override"
},
"_condition": "@(context.Product != null)"
}
}
},
"backend": {
"forward-request": ""
},
"outbound": "",
"on-error": ""
}
}
这在任务中也有说明,请参考如下所示的部分
您可以尝试将parameter.xml转换为parameter.json。Azure资源组部署任务不支持解析XML文件。@HughLin MSFT在internet上找到的最佳解决方案是将所有APIM的策略放在一行中,而不是将其传递给部署任务。但另一方面,由于采用单行格式,很难对其添加一些更改。问题是,我们试图在不支持的情况下将XML转换为parameter.json。谢谢你的帮助