I have a job in azure-pipelines that receives a variable number of dependencies. It could have zero dependencies, or "n" dependencies depending what previous jobs were executed before this one.
Let's see an example:
file: "dependent-job.yml"
parameters:
- name: Dependencies
type: Array
default:
- Job1
- Job2
Jobs:
- job: Variousdependencies
name: MyJob
${{ if parameters.Dependencies }}
dependsOn: ${{ parameters.Dependencies }}
condition: |
and(eq(dependencies.Job1.result, 'Succeeded'),
eq(dependencies.Job2.result, 'Succeeded'),
eq(variables[MyJobEnabled,'True'),
eq('${{ parameters.ForceJob }}','True')
)
If I have 3 dependencies, I need to add another dependency in condition:
condition: |
and(eq(dependencies.Job1.result, 'Succeeded'),
eq(dependencies.Job2.result, 'Succeeded'),
eq(dependencies.Job3.result, 'Succeeded'),
eq(variables[MyJobEnabled,'True'),
eq('${{ parameters.ForceJob }}','True')
)
I would like to generate the lines that check if the previous jobs ended sucessfuly using the each syntax. This is what I tried:
condition: |
and(${{ each job in dependencies }}
eq(dependencies.{{ job }}.result, 'Succeeded'),
eq(variables[MyJobEnabled,'True'),
eq('${{ parameters.ForceJob }}','True')
)
but I received the following error when trying to run it:
The directive 'each' is not allowed in this context. Directives are not supported for expressions that are embedded within a string. Directives are only supported when the entire value is an expression.