Describe the bug
Given a parameterless resource template, when attempting to push or validate the template using the AzOps pipelines, the jq statement throws an error statement in the pipeline log.
jq: error (at <stdin>:76): null (null) has no keys
This is not super critical, as the Powershell ConvertFrom-Json -AsHashtable seems to handle the error case just fine, however the error log could be interpreted as an actual fault.
Scripts in question:
Steps to reproduce
- A parameterless main.bicep:
var location = 'westeurope'
resource example 'Microsoft.Storage/storageAccounts@2023-05-01' = {
name: 'st${uniqueString(resourceGroup().id)}'
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
- Build it and show Bicep omits parameters entirely rather than emitting {}:
$ bicep build main.bicep --outfile main.json
$ jq 'has("parameters")' main.json
false
$ jq '.parameters | with_entries(select(.value.defaultValue == null))' main.json
jq: error: null (null) has no keys
Note:
The is not a bicep specific error, and is even reproducible with the following bare-bones ARM template:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": []
}
Proposed Solution:
Add a safeguard to the jq statement, which defaults to an empty object in case .parameters does not exist:
Old: .parameters | with_entries(select(.value.defaultValue == null))
New: .parameters // {} | with_entries(select(.value.defaultValue == null))
Describe the bug
Given a parameterless resource template, when attempting to push or validate the template using the AzOps pipelines, the
jqstatement throws an error statement in the pipeline log.jq: error (at <stdin>:76): null (null) has no keysThis is not super critical, as the Powershell
ConvertFrom-Json -AsHashtableseems to handle the error case just fine, however the error log could be interpreted as an actual fault.Scripts in question:
Steps to reproduce
Note:
The is not a bicep specific error, and is even reproducible with the following bare-bones ARM template:
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [] }Proposed Solution:
Add a safeguard to the
jqstatement, which defaults to an empty object in case.parametersdoes not exist:Old:
.parameters | with_entries(select(.value.defaultValue == null))New:
.parameters // {} | with_entries(select(.value.defaultValue == null))