Reputation: 1
Q1: I have a single job in ADO YAML pipeline which have 4-5 tasks under steps. I want to trigger those tasks based on few conditions so I've used ADO Expressions. But now i want to skip the taskB when taskA fails. By default it should happen but seems like my task condition is overriding the continueonerror:false
Can you suggest how to do this ? tried alternative workaround: Multi Job Pipeline setup with 1 task in 1 job & it works fine for us, but want to know how we can setup for multiple tasks in a single job ?
Q2 : Even if i can get taskA status as a variable using REST API & set variable concepts, how can i add multiple conditions in task.something like " variable1=succeeded & variable2 = p1 or variable3 = p2 "
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops
Sample yaml
parameters:
variables:
trigger:
steps:
task: A
continueonerror:false
condition: or(eq(v1, p3), eq(v2, 3), eq(v4, 5))
task: B
continueonerror:false
condition: or(eq(v1, p1), eq(v2, 6))
task: C
continueonerror:false
condition: or(eq(v1, p2), eq(v2, 8))
Upvotes: 0
Views: 1072
Reputation: 5877
According to your expectation to skip TaskB
if TaskA
fails, you may consider adding succeeded()
as part of the condition in TaskB
together with your other evaluations. Kindly take the following sample YAML for a reference.
trigger: none
parameters:
- name: p1
default: 1
- name: p2
default: 2
- name: p3
default: 3
variables:
v1: 2
v2: 6
v3: 2
v4: 5
steps:
- script: |
echo A
echo "##vso[task.logissue type=error]Simulate task failure."
exit 1
name: TaskA
# continueOnError: true
condition: or(eq(variables['v1'], ${{ parameters.p3 }}), eq(variables['v2'], 3), eq(variables['v4'], 5))
- script: echo B
name: TaskB
condition: and(succeeded(), or(eq(variables['v1'], ${{ parameters.p1 }}), eq(variables['v2'], 6)))
- script: echo C
name: TaskC
condition: and(succeededOrFailed(), or(eq(variables['v1'], ${{ parameters.p2 }}), eq(${{ parameters.p2 }}, 8)))
When TaskA
failed the condition evaluation of succeeded()
for TaskB
would be False
; hence TaskB
was skipped.
TaskC
uses succeededOrFailed()
in its condition and will continue to run, even if a previous dependency has failed, unless the run was canceled.
See more information on Specify conditions.
Upvotes: 1