Как передать значения запроса предупреждения, заканчивающиеся двойными кавычками, в файл параметров шаблона ARM

#json #azure-devops #azure-pipelines #arm-template

Вопрос:

Я использую конвейеры Azure для автоматизации оповещений на основе запросов журнала. Сначала я передаю значения параметров среды выполнения в переменную Azure, а затем заменяю файл parameter.json запросом с помощью задачи замены токена в конвейере. Когда я передаю запросы, которые не заканчиваются двойными кавычками», задача развертывания группы ресурсов выполняется успешно. Но когда я передаю запрос, который уже заканчивается двойными кавычками, происходит сбой.

Напр.:

Это мой базовый запрос.

 "ApiManagementGatewayLogs | where ApiId == ""my-api"" | where ResponseCode == 429 | where _SubscriptionId==""xxxxxxxxxxxxxxxxxxxxxxx"""  

поскольку мой параметр времени выполнения имеет тип «строка», передаю его в виде одной строки, как показано ниже

 ApiManagementGatewayLogs| where ApiId == ""my-api""| where ResponseCode == 429| where _SubscriptionId==""xxxxxxxxxxxxxxxxxxxxxxx""  

Но развертывание завершилось неудачно с ошибкой ниже

 Template deployment validation was completed successfully. Starting Deployment. Deployment name is digitalAlerts There were errors in your deployment. Error code: DeploymentFailed. ##[error]At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details. ##[error]Details: ##[error]BadRequest: {  "error": {  "message": "The request had some invalid properties",  "code": "BadArgumentError",  "correlationId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",  "innererror": {  "code": "SyntaxError",  "message": "Request is invalid and cannot be processed: Syntax error: SYN0001: I could not parse that, sorry. [line:position=0:0]. Query: 'let ['ApiManagementGatewayLogs'] = view () { datatable(['TenantId']:string,['TimeGenerated']:datetime,['OperationName']:string,['CorrelationId']:string,['Region']:string,['IsRequestSuccess']:bool,['Category']:string,['TotalTime']:long,['CallerIpAddress']:string,['Method']:string,['Url']:string,['ClientProtocol']:string,['ResponseCode']:int,['BackendMethod']:string,['BackendUrl']:string,['BackendResponseCode']:int,['BackendProtocol']:string,['RequestSize']:int,['ResponseSize']:int,['Cache']:string,['CacheTime']:long,['BackendTime']:long,['ClientTime']:long,['ApiId']:string,['OperationId']:string,['ProductId']:string,['UserId']:string,['ApimSubscriptionId']:string,['BackendId']:string,['LastErrorElapsed']:long,['LastErrorSource']:string,['LastErrorScope']:string,['LastErrorSection']:string,['LastErrorReason']:string,['LastErrorMessage']:string,['ApiRevision']:string,['ClientTlsVersion']:string,['RequestHeaders']:dynamic,['ResponseHeaders']:dynamic,['BackendRequestHeaders']:dynamic,['BackendResponseHeaders']:dynamic,['RequestBody']:string,['ResponseBody']:string,['BackendRequestBody']:string,['BackendResponseBody']:string,['Errors']:dynamic,['TraceRecords']:dynamic,['SourceSystem']:string,['Type']:string,['_ResourceId']:string,['_SubscriptionId']:string)[] };restrict access to (*);rnApiManagementGatewayLogs\n| where ApiId == \"my-api\"\n| where ResponseCode == 429\n| where _SubscriptionId==\"xxxxxxxxxxxxxxxxxxxxxxxx\"\n\n'"  }  } } ##[error]Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment?view=azure-devops#troubleshooting ##[error]Task failed while creating or updating the template deployment.  

Ищете 2 решения:

  • Со стороны конвейера, как я могу передавать запросы в том же формате , что и мой базовый запрос, где пользователи могут легко передавать свои запросы, которые заменят мои параметры.json в правильном формате
  • Во-вторых, как можно избежать вышеуказанной проблемы, передавая запросы с окончанием двойных кавычек.

Примечание. уже пытались изменить запрос, заменив » на/, но не решили проблему