Reputation: 23
I'm using "Azure resource group deployment task" in the azure pipeline to deploy API management service. And one of my parameters is "policy content" (xml content passing like a string).
What I see right now this task converts this string:
"<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>"
to this:
"'<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>'"
It adds a single quote to the start and to the end of the input string. Due to this behavior, I have this error: "Data at the root level is invalid. Line 1, position 1." and deployment fails.
I pass this parameter via "Override template parameters" -apimPolicy "$(ApimServicePolicy)"
Any thoughts on how to skip these single quotes adding?
Upvotes: 0
Views: 2175
Reputation: 19461
For this issue, the problem could be parameter.xml
file cannot be parsed by Azure resource group deployment task. Azure resource group deployment task only supports parsing parameter files in json
format.
You can search out many Convert XML To JSON tools through Google, for example:
{
"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": ""
}
}
This is also stated in the task document, please refer to the part as shown below.
Upvotes: 0