I am trying to use output variables to pass values between stages. I create an output variable and populate it.
In the second stage I use the variable inside a script and it works as expected.
However, when I try to pass this into the template it doesn't work. How do I pass this value into the template?
stages:
- stage: AllocateEnvironment
jobs:
- job: AllocateEnvironment
steps:
- script: |
environment="test"
echo "##vso[task.setvariable variable=Environment;isOutput=true]$environment"
name: AllocateEnvironment
- stage: ScaleUpEnvironment
dependsOn: AllocateEnvironment
variables:
Environment: $[stageDependencies.AllocateEnvironment.AllocateEnvironment.outputs['AllocateEnvironment.Environment']]
jobs:
- job: ScaleUpEnvironment
displayName: 'Scale up environment'
steps:
- script: |
echo "Environment: $(Environment)"
- template: scaler.yaml
parameters:
environment: $[stageDependencies.AllocateEnvironment.AllocateEnvironment.outputs['AllocateEnvironment.Environment']]
To use the value of output variable on the steps in a different stage, you need to use the expression
stageDependencies.STAGE.JOB.outputs['TASK.VARIABLE']
to map the output variable as a general variable at a job level. Then on the steps of this job, you can directly call the general variable using the expression$(VarName)
to pass the value.For you case, there are two ways to pass the value of output variable to the step template. See below examples as reference.
1. Directly call the general variable mapped for the output variable in the step template.
azure-pipelines.yml
Step-Templates/insert-step.yml
2. Pass the value from the general variable to a parameter in the step template. Just like as you are doing.
azure-pipelines.yml
Step-Templates/insert-step.yml