Home > Blockchain >  How to Consume a Return Parameter from a Bicep Template Deployment?
How to Consume a Return Parameter from a Bicep Template Deployment?

Time:11-25

I currently try to Consume a return property from a CLI Task which deploys the Bicep Template for a Log Analytics workspace, this is done by:

output logAnalyticsWorkspaceResourceId string = logAnalyticsWorkspace.id The Task is of type: AzureCLI@2 is named: LogWorkSpace

In the Next Task also of type AzureCLI@2 I want to pass the logAnalyticsWorkspace.id to the Creating of the Storage account, However I can't find the right Syntax to do this. At one point I read that i Should use: LogWorkSpace.logAnalyticsWorkspaceResourceId but this keeps empty.

Any Help is appreciated.

CodePudding user response:

In Azure Pipeline, the returned parameter of bicep template in the azure cli task cannot be used directly in the next task. It only works on the current task.

To let the parameter value pass to next tasks, you need to save the value as Pipeline variable with logging command.

for example:

echo "##vso[task.setvariable variable=customvariablename;]parametervalue"

Then you can use the Pipeline value $(customvariablename) in the next tasks.

Here is an Azure CLI task example:

steps:
- task: AzureCLI@2
  displayName: 'Azure CLI '
  inputs:
    azureSubscription: azure
    scriptType: ps
    scriptLocation: inlineScript
    inlineScript: |
     
         az deployment group create xxx
         
         $out = az deployment group show -g $(resourceGroup) -n azuredeploy | convertfrom-json | foreach properties | foreach outputs
         
         $provisionOutputs = [PSCustomObject]@{}
         $out | Get-Member -MemberType NoteProperty | ForEach-Object {
         
                $name = $_.name
                $provisionOutputs | Add-Member -MemberType NoteProperty -Name $name -value $out.$name.value
                Write-Host "##vso[task.setvariable variable=$($name);isOutput=true]$($out.$name.value)"
        }

For more detailed info, you can refer to this doc: Set variables in scripts

  • Related