I need to run a publish task in my build definition but only if a certain task before it has failed. If the other task passes I want this to be ignored and not run.
Is there a way of doing this?
I was hoping that I could set an output variable based on the task success and then use that variable in a custom condition to run the task if it's failed.
I can't see how to set an output variable if the task fails. Is this possible?
You could add two same tasks in the pipeline, one with the condition ((Var1==A || Var1==B || Var1==C) && (Var2==2)) and another with condition ((Var1==A) &&(Var2==1)) , this should be work.
You can try set variables : enabled = false , then use the variable in YAML file. If set this way, this task will not run in the job. This method is mentioned in this case, you can refer to it for details.
Share variables between Tasks across the Jobs (of the same Stage) We need to use the isOutput=true flag when you desire to use the variable in another Task located in another Job. Navigate to Stage1_Job1_Task1 and add isoutput = true flag to the Logging Command which let's us to access the value outside the Job.
Only when a previous task has failed
.If you want to run the task only if last/specific task failed:
Suppose your specific task (the one you examine in regards to its status) is called A
. The goal is to call another build task (let's say B
) only in case A
fails.
task.A.status
and set to success
C
and schedule it right after A
; condition it to only run if A
fails - there's a standard condition for thatC
should only do one thing - set task.A.status
build variable to 'failure' (like this, if we are talking PowerShell: Write-Host "##vso[task.setvariable variable=task.A.status]failure"
)B
is scheduled sometime after C
and is conditioned to run in case task.A.status
equals failure
, like this: eq(variables['task.A.status'], 'failure')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With