我正在azure管道中使用“ Azure资源组部署任务”来部署API管理服务。我的参数之一是“策略内容”(xml内容像字符串一样传递)。
我现在看到的此任务将转换此字符串:
"<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>"
对此:
"'<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>'"
它将单引号添加到输入字符串的开头和结尾。 由于这种行为,我出现以下错误:“根级别的数据无效。第1行,位置1。” ,并且部署失败。
我通过“替代模板参数” -apimPolicy "$(ApimServicePolicy)"
传递了此参数
是否有关于如何跳过这些单引号的想法?
答案 0 :(得分:0)
对于此问题,问题可能是Azure资源组部署任务无法解析parameter.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": ""
}
}
任务document中也对此有所说明,请参阅下面的部分。