How to make task dependent on a specific task on azure pipelines? My goal is to run tasks C and D if and only if task B failed.
I have tried using the condition: failed()
but if task A failed it will run tasks C and D, which is incorrect.
Is there a way to specify which task another task is dependent on?
- task: A
inputs:
command:
repository:
Dockerfile:
tags:
displayName: 'Build test image'
- task: B
inputs:
fullImageNameAndTag:
displayName: 'test image'
condition: succeeded()
- task: C
inputs:
targetPath:
displayName: 'Download test image'
condition: ?
- task: D
inputs:
targetPath:
displayName: 'Download test2 image'
condition: ?
This should do the trick - uncomment lines # exit 1
to fail a specific task:
trigger: none
pool:
vmImage: 'ubuntu-latest'
steps:
- script: |
echo "This is task A"
# exit 1
displayName: 'Task A'
# Allow the following tasks to run, in case of failure
# If task is successful then $(Agent.JobStatus)=Succeeded
# If task fails then $(Agent.JobStatus)=SucceededWithIssues
continueOnError: true
- script: |
echo "This is task B"
# exit 1
displayName: 'Task B'
condition: eq(variables['Agent.JobStatus'], 'Succeeded')
- script: |
echo "This is task C"
displayName: 'Task C'
condition: failed() # same as eq(variables['Agent.JobStatus'], 'Failed')
- script: |
echo "This is task D"
displayName: 'Task D'
condition: failed() # same as eq(variables['Agent.JobStatus'], 'Failed')
Notes:
continueOnError: true
allows the following tasks to run if the task fails, but sets variable Agent.JobStatus=SucceededWithIssues
Agent.JobStatus==Succeeded
Agent.JobStatus==Failed