Forum Discussion

David_Hughes's avatar
David_Hughes
Copper Contributor
Jul 24, 2023
Solved

Unable to pass dynamic variables between stages in DevOps

I currently have two stages in a YAML devops release pipeline.  The first stage pickups up the build and deploys the logic app. outputting it's ID at the end of the deployment. The second stage uses...
  • David_Hughes's avatar
    Jul 27, 2023

    So found the solution, and its in 5 parts.
    1. In the YAML pipeline create an environmental variable - here it's called ManagedID.  Ensure it can be edited by the user during the pipelines execution.
    2. Line 24 - the output from the deployment - assign it the same name
    3. Line 34 - use Write-Host not echo as for some reason echo removed the first curly bracket rendering the JSON useless.
    4. Point the global variable at the environment variable, thus the line becomes:

    write-host "##vso[task.setvariable variable=ManagedID;isOutput=true]${env:MANAGEDID}"

    5. Line 43 - In the next stage add a dependency to the stage based on the previous stage
    6. Line 45 - 46 - Grab the Global variable for use in that stage:
    dependsOn:
    - BuildandDeployLogicApp
    variables:
    - name: LAManagedID
    value: $[stageDependencies.BuildandDeployLogicApp.PickupAndDeploy.outputs['CaptureMD.ManagedID']]

    The problem was caused by the echo command missing the bracken off and compounded by the variable being destroyed at the end of the stage, hence the push up to an environment variable then back to a global.

Resources