'Azure Devops Pipeline YAML - Dependencies Filtered Array In Conditional
I am trying to use the filtered array syntax in a conditional for a stage
stages:
- stage: One
jobs:
- job:
steps:
- script: echo 'One'
- stage: Two
dependsOn: One
jobs:
- job:
steps:
- script: echo 'Two'
- stage: Three
dependsOn: One
jobs:
- job:
steps:
- script: throw
- stage: Four
condition: containsValue(dependencies.*.result, 'Failed')
dependsOn:
- One
- Two
- Three
jobs:
- job:
steps:
- script: echo 'Four'
Based on my understanding of the filtered array syntax, this should access the 'result' property of all of the stage dependencies, and since stage Three always fails, the expression should be evaluate true. However, when I run the pipeline, stage 4 is still skipped, and the only output given is 'The job was skipped'.
I have tried to debug to the best of my abilities but unfortunately you can't access the dependencies within job or step contexts (since in those contexts you use stageDependencies).
Any help would be greatly appreciated
Solution 1:[1]
try dumping all dependencies in a stage four variable using convertToJson(dependencies) and convertToJson(stageDependencies) and printing in console - that might give you a clue what values are present and what you are checking
For example:
stages:
- stage: A
jobs:
- job: A1
variables:
myDependencies: $[convertToJson(dependencies)]
steps:
- script: |
echo "dependencies- $(myDependencies)"
echo "##vso[task.setvariable variable=myAvar;isoutput=true]myval"
- stage: B
dependsOn: A
variables:
- name: stage_stageDependencies
value: $[convertToJson(stageDependencies)]
- name: stage_dependencies
value: $[convertToJson(dependencies)]
jobs:
- job: B1
steps:
- script: |
echo "##vso[task.setvariable variable=myBvar;isoutput=true]myBval"
- job: B2
dependsOn: B1
variables:
- name: B2Job_dependencies
value: $[convertToJson(dependencies)]
steps:
- script: |
echo "stage_stageDependencies: $(stage_stageDependencies)"
echo "stage_dependencies: $(stage_dependencies)"
echo "B2Job_dependencies: $(B2Job_dependencies)"
Note: There are two objects stageDependencies and dependencies (for jobs). And they get populated if dependsOn are defined.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
