I have a pipeline that runs two stages. The stages are essentially identical, except one depends on the other. They both reference a template that contains two jobs, one job depending on the other. The first job creates an output variable and the second job consumes it.
The problem is that there are two JobA's and two JobB's and JobB doesn't seem to know which JobA is the correct one. Here's the YAML:
# azure-pipelines.yaml
stages:
- stage: deployQA
jobs:
- template: stage-template.yaml
parameters:
environment: QA
- stage: deployStaging
dependsOn: deployQA
condition: succeeded()
jobs:
- template: stage-template.yaml
parameters:
environment: STAGING
# stage-template.yaml
parameters:
environment: ''
jobs:
- job: preDeploy
variables:
artifactName: preDeploy-${{ parameters.environment }}
environment: ${{ parameters.environment }}
steps:
- checkout: none
- publish: $(Pipeline.Workspace)
artifact: $(artifactName)
- pwsh: |
echo "##vso[task.setvariable variable=artifactName;isOutput=true]$($env:ARTIFACTNAME)"
name: outputVars
- job: deployment
dependsOn: preDeploy
variables:
artifactName: $[dependencies.preDeploy.outputs['outputVars.artifactName']]
steps:
- checkout: none
- download: current
artifact: $(artifactName)
The problem is toward the bottom of the second file on this line:
artifactName: $[dependencies.preDeploy.outputs['outputVars.artifactName']]
When the QA stage is run, $[dependencies.preDeploy.outputs['outputVars.artifactName']]
resolves to preDeploy-QA
and when the Staging stage is run, it also resolves to preDeploy-QA
. Looking at the logs, I can see them being resolved incorrectly:
// 2_deployment.txt
Variables:
artifactName:
Parsing expression: <dependencies.preDeploy.outputs['outputVars.artifactName']>
Evaluating: dependencies['preDeploy']['outputs']['outputVars.artifactName']
Result: 'preDeploy-QA'
// 2_deployment (1).txt
Variables:
artifactName:
Parsing expression: <dependencies.preDeploy.outputs['outputVars.artifactName']>
Evaluating: dependencies['preDeploy']['outputs']['outputVars.artifactName']
Result: 'preDeploy-QA'
I am doing something wrong here? Or is this a bug?
You can see the YAML and logs [here][1].
[1]: https://dev.azure.com/lolinctest/PublicTest/_build/results?buildId=506&view=results