Parsing error with Azure Bicep files in SonarQube
The Issue
We saw an issue with our SonarQube 10.3 Developer Edition (that is running as a Docker image hosted in Azure) when it was doing the analysis of a project that included Azure Bicep files.
The Azure DevOps pipeline that triggered the SonarQube analysis was not failing, but within the SonarQube analysis step an error was reported in the task log
1INFO: Sensor IaC AzureResourceManager Sensor is restricted to changed files only
2INFO: 1 source file to be analyzed
3##[error]ERROR: Cannot parse 'AzureServices/QueryPack.bicep:89:1'
The Solution
Turns out the problem was related to parsing Bicep files for App Insights Query packs.
If the Bicep resource for the query contains a body
property that starts with a comment e.g.
1resource querypacks_DefaultQueryPack 'microsoft.operationalInsights/querypacks/queries@2019-09-01-preview' = {
2 parent: QueryPack
3 name: ...
4 properties: {
5 displayName: ...
6 description: ..
7 body: '// 35 is ABC\r\n// 40 is XYZ \r\nrequests\r\n| where name has "myfacade.svc"\r\n| order by timestamp desc\r\n| where name !has "GET"\r\n| summarize count() by name, resultCode\r\n| render columnchart'
We get the error ##[error]ERROR: Cannot parse 'AzureServices/QueryPack.bicep:89:1
We can fix this by not starting the body
with a comment, just moving the comment to the end of the body
i.e.
1resource querypacks_DefaultQueryPack 'microsoft.operationalInsights/querypacks/queries@2019-09-01-preview' = {
2 parent: QueryPack
3 name: ...
4 properties: {
5 displayName: ...
6 description: ..
7 body: 'requests\r\n| where name has "myfacade.svc"\r\n| order by timestamp desc\r\n| where name !has "GET"\r\n| summarize count() by name, resultCode\r\n| render columnchart\r\n// 35 is ABC\r\n// 40 is XYZ'