jq: error: null (null) has no keys for any template without a parameters object

Open Beginner friendly
#956 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
90/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
powershell
Domain
ci-cd

Research direction

Start in src/functions/Invoke-AzOpsPush.ps1 around line 396 and inspect the jq statement applied to .parameters. Reproduce it with a parameterless ARM or Bicep template, then verify that validation or push no longer logs the null-keys error while still handling templates with parameters.

Written by the indexing model from the issue text.

Description

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

  1. 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'
}
  1. 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))

Dominant language
PowerShell
Stars
420
Forks
174
Avg merge
16d 18h
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/AzOps

All issues in Azure/AzOps

Similar issues

More DevOps issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.