79302729

Date: 2024-12-23 09:59:01
Score: 0.5
Natty:
Report link

Handle bash output and passing to bicep

Hello Frederic Gauthier, seems like you already found a solution to your problem, I am just posting it here for ease of other folks who are facing similar issue on SO. Please feel free to add any points/your inputs to this if required.

Thanks Charles Duffy for sharing the right input. You just need to install jq by making changes in inlineScript section. This will process the JSON output in the format you need by transforming the array in JSON into required format.

jq Transformation:

Sample Inlinescript:

inlineScript: |
  $(var-bashPreInjectScript)
  
  templateFile=hub/hubconnectivite.bicep

  echo "Deploying $templateFile using ${{ parameters.deployOperation }} operation"

  preDeploymentRgList=$(az group list --subscription "$(var-hub-subscriptionId)" --query "[].name" -o json)

  preDeploymentRgListFormatted=$(echo "$preDeploymentRgList" | jq -r 'map("\"" + . + "\"") | join(", ")' | sed 's/^/(/;s/$/)/')

  echo "Formatted Resource Groups: $preDeploymentRgListFormatted"
 
  az deployment sub ${{ parameters.deployOperation }} \
    --name hubconnectivite${{ parameters.deploymentRegion }} \
    --location ${{ parameters.deploymentRegion }} \
    --subscription $(var-hub-subscriptionId) \
    --template-file $templateFile \
    --parameters \
        preDeploymentRgListName="$preDeploymentRgListFormatted" \
        subscriptionId='$(var-hub-subscriptionId)' \
        location='${{ parameters.deploymentRegion )}}' \
        otherParameter='$(var-other-parameter)'

  # Post-injection script (if any)
  $(var-bashPostInjectScript)

Refer:

Convert a JSON array to a bash array of strings - Stack Overflow for related query information

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): facing similar issue
  • High reputation (-1):
Posted by: Vinay B