I can’t figure out what am I doing wrong with variable dependencies between jobs.
I have the following pipeline, taken almost verbatim from Microsoft documentation:
trigger: none
stages:
- stage: build
jobs:
- job: A
steps:
- powershell: |
Write-Output "##vso[task.setvariable variable=MyVar;isOutput=true]zomg"
name: ProduceVar
- script: echo $(ProduceVar.MyVar) # Prints out zomg.
- job: B
dependsOn: A
condition: eq(dependencies.A.outputs['ProduceVar.MyVar'], 'zomg') # Fails, B does not get executed.
variables:
varFromA: $[ dependencies.A.outputs['ProduceVar.MyVar'] ]
steps:
- script: echo $(varFromA) # Does not print out the variable, it is not mapped.
The condition for job B
fails with the following information:
Started: Yesterday at 16:19
Duration: 15h 33m 54s
Evaluating: eq(dependencies['A']['outputs']['ProduceVar.MyVar'], 'zomg')
Expanded: eq(Null, 'zomg')
Result: False
If I remove that check, the variable dependency is not picked up in the last script which tries to output mapped variable.
The output in this case looks like this:
Pool: Azure Pipelines
Image: ubuntu-latest
Agent: Azure Pipelines 10
Started: Yesterday at 16:22
Duration: 5s
Job preparation parameters
Variables:
varFromA:
Parsing expression: <dependencies.A.outputs['ProduceVar.MyVar']>
Evaluating: dependencies['A']['outputs']['ProduceVar.MyVar']
Expanded: Null
Result: ''
ContinueOnError: False
TimeoutInMinutes: 60
CancelTimeoutInMinutes: 5
Expand:
MaxConcurrency: 0
########## System Pipeline Decorator(s) ##########
Begin evaluating template 'system-pre-steps.yml'
Evaluating: eq('true', variables['system.debugContext'])
Expanded: eq('true', Null)
Result: False
Evaluating: resources['repositories']['self']
Expanded: Object
Result: True
Evaluating: not(containsValue(job['steps']['*']['task']['id'], '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Expanded: not(containsValue(Object, '6d15af64-176c-496d-b583-fd2ae21d4df4'))
Result: True
Evaluating: resources['repositories']['self']['checkoutOptions']
Result: Object
Evaluating: pair['key']
Result: 'fetchDepth'
Evaluating: pair['value']
Result: '1'
Evaluating: pair['key']
Result: 'lfs'
Evaluating: pair['value']
Result: 'false'
Finished evaluating template 'system-pre-steps.yml'
********************************************************************************
Template and static variable resolution complete. Final runtime YAML document:
steps:
- task: 6d15af64-176c-496d-b583-fd2ae21d4df4@1
inputs:
repository: self
fetchDepth: 1
lfs: false
MaxConcurrency: 0
What makes this even more painful for me: I have other pipelines, where this works perfectly fine, even referencing jobs from different stages.
What silly mistake am I making here?
2
Answers
This turned out to be a very weird bug in Azure Pipelines.
The problem is the stage name
build
in combination with the Azure DevOps organization/project that I am using.Removing the stage definition, or renaming the stage to anything other than
build
resolves the issue.Keeping the stage name
build
and running this in projects from other organizations resolves the issue.Pray for us all...
I copied your yaml, without any changes,it’s working fine on my side. But the
Evaluating
is different with yours:Please follow below items for a check:
Is the yaml shared exactly same with your real one? Do you have stage, deployment job in your real yaml?
Which branch do you have the yaml? Make sure you are running on the correct branch.