i have an azure pipeline that is what it looks like in pipeline.yml represented below. i'm trying to pass the variable set in stage to a job in another stage like a parameters. the problem is that it doesn't work:
job_template1.yml:
jobs:
- job: A1
steps:
- script: echo ##vso[task.setvariable variable=shouldrun;isOutput=true]true
name: printvar
job_template2.yml:
parameters:
myparam: ''
jobs:
- job: B1
steps:
- script: echo ${{ parameters.myparam }}
pipeline.yml
stages:
- stage: A
jobs:
- template: job_template1.yml
- stage: B
jobs:
- template: job_template2.yml
parameters:
myparam: $[ stageDependencies.A.A1.outputs['printvar.shouldrun'] ]
the final echo is: $[ stageDependencies.A.A1.outputs['printvar.shouldrun'] ]
any idea on how to fix it?
i even tried changing the pipeline in:
stages:
- stage: A
jobs:
- job: A1
steps:
- script: echo ##vso[task.setvariable variable=shouldrun;isOutput=true]true
name: printvar
- stage: B
jobs:
- template: job_template2.yml
parameters:
myparam: $[ stageDependencies.A.A1.outputs['printvar.shouldrun'] ]
without any luck
I have something similar in our templated pipeline. One of the things you forgot to add is the dependsOn tag and you are not using quotes (") around the script.
In order to get it to work, you will need to save the variable that you set in Stage A in a variable for stage B, as shown below.
Here is a sample code in 1 file. But splitting these up in multiple templates shouldn't cause any issues.
Hope this helps.