I’m getting an error FinalJob Job depends on unknown TestJob job
azure-pipelines.yml
- ${{ if eq(parameters.FLAG, false) }}:
- job: TestJob
displayName: Testing job
dependsOn: AnotherJob
condition: succeeded()
steps:
- checkout: none
- template: my-template.yml
parameters:
TARGET: ${{ parameters.TARGET }}
- ${{ if eq(parameters.FLAG, true) }}:
- job: TestJob2
displayName: Testing job 2
dependsOn: AnotherJob
condition: succeeded()
steps:
- checkout: none
- template: my-template2.yml
parameters:
TARGET: ${{ parameters.TARGET }}
- job: FinalJob
displayName: Final Job..
dependsOn:
- TestJob
- TestJob2
condition: |
or
(
eq(dependencies.TestJob.result, 'Succeeded'),
eq(dependencies.TestJob2.result, 'Succeeded')
)
steps:
- checkout: none
- task: Bash@3
displayName: 'Final script'
inputs:
targetType: 'filePath'
filePath: './scripts/my-script.sh'
What I would like?
I’d like to call FinalJob
if TestJob
or TestJob2
work properly. How can i do that? is it not working because the if before TestJob
and TestJob2
?
What I tried?
I made it work but adding my parameters.FLAG
as part of the job condition.. but it displays the job name in azure platform and I don’t want that..
2
Answers
I can reproduce the same issue when using the YAML sample.
The cause of the issue is that the dependsOn field will read the job name at the compile time.
Since the if expression will let one of the job not be read at compile time, it will cause the
unknown TestJob job
issue.To solve this issue, I suggest that you can set a variable in YAML Pipeline to determine which job to run and use it in dependsOn field.
For example:
Result:
Two ways to get the goal, just simple-copy and try:
method1.yml
method2.yml
here using
exit 1
to simulate the job failure.