--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Recently Changed Pages:

View All Pages

View All Tags


WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.

Pages with comments

View All Comments


Parse Bicep Output in Azure DevOps Pipeline

In Azure ARM and YAML Project I already showed how to parse the output in a pipeline for ARM templates using Powershell. I now have a use case for parsing the output from BICEP in a pipeline using bash.

So we will first do a bicep deployment in which we will parse the output and then show how you can find the variable in the next task.

Deployment Task

- task: AzureCLI@2 
  displayName: Set
    azureSubscription: $(azureServiceConnection)
    scriptType: bash
    scriptLocation: inlineScript
    inlineScript: |
      set -e
      az account set --subscription $(subName)
      echo '##[Section]Deploy vnet & private endpoint network config'
      az deployment group create \
        --resource-group $(rgName) \
        --name "hub-vnet-$deploymentSuffixAttempt" \
        --template-file ./hub/hub-vnet.bicep \
        --parameters deploymentSuffix=$deploymentSuffixAttempt \
        --parameters locationShort=$(regionShort) \
        --parameters subscriptionId=$(subName) \
        --parameters environment=$(environment) \
        --parameters hubVnetName=$(vnetName) \
        --parameters azureFirewall=$(AzureFirewallIP)
      echo 'Parse deployment output naar Azure DevOps & Bash variabelen'
      deploymentOutput=$(az deployment group show \
        --resource-group $(rgName) \
        --name $(vnetName)-$deploymentSuffixAttempt \
        --query properties.outputs | jq -c 'to_entries[] | [.key, .value.value]')
      while IFS=$'\n' read -r c; do
        outputname=$(echo "$c" | jq -r '.[0]')
        outputvalue=$(echo "$c" | jq -r '.[1]')
        echo "Log variabele: $outputname : $outputvalue"
        declare $outputname=$outputvalue 
        echo "##vso[task.setvariable variable=$outputname;isoutput=true]$outputvalue"
      done <<< "$deploymentOutput"


In this task you can see the variable, but watch it, the output name will have a prefix of “AZURECLI4_”. So if the var is called “varName” it will be available as “AZURECLI4_varName”

- task: AzureCLI@2 
  displayName: Check
    azureSubscription: $(azureServiceConnection)
    scriptType: bash
    scriptLocation: inlineScript
    inlineScript: |
      set -e
      #Temp: check for thevar
      printenv | sort
You could leave a comment if you were logged in.
parsebicepoutputinpipeline.txt · Last modified: 2023/05/22 09:20 by sjoerd