Reputation: 419
I am trying to pass a variable from one job to multiple non-dependent jobs. It works for dependent jobs. However it is not working for non-dependent jobs. I have yaml pipeline defined like this.
jobs:
- job: JobA
steps:
- task: Bash@3
name: var_test
inputs:
targetType: 'inline'
script: |
myVar=demo-value
echo "##vso[task.setvariable variable=myVarNew;isOutput=true]$myVar"
- job: JobB
dependsOn: JobA
variables:
- name: newVar2
value: $[ dependencies.JobA.outputs['var_test.myVarNew'] ]
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "$(newVar2)"
- job: JobC
dependsOn: JobB
variables:
- name: newVar2
value: $[ dependencies.JobA.outputs['var_test.myVarNew'] ]
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
echo "$(newVar2)"
It works fine in JobB. But when I tried it in different downstream job like jobC it doesn't work. Also I can't set the variable in every job as manual validation agentless job is also there in between. I want to use same variable in different non dependent jobs within same stage. Please help. Thanks.
Upvotes: 0
Views: 950
Reputation: 4301
dependencies.X.outputs
relies on X having been declared as a dependency. If it's not there, then Azure Pipelines can't really know to track it as one for that job (with the sole exception that a Job implicitly dependsOn
the preceding job unless this is explicitly set.
In your case, though, because JobB
depends on JobA
and JobC
depends on JobB
, the following is equivalent (even if a little redundant):
- job: JobC
dependsOn:
- JobA
- JobB
...
It's redundant for dependancy graph purposes, but it satisfies the need for a dependency to be declared so that you can access its output variables.
Upvotes: 2