问题
TFS build allows to specify conditions for running a task: reference.
The condition I would like to define is: a specific task [addressed by name or other mean] has failed.
This is similar to Only when a previous task has failed
, but I want to specify which previous task that is.
Looking at the examples I don't see any condition that is addressing a specific task outcome, only the entire build status.
Is it possible? any workaround to achieve this?
回答1:
It doesn't seem like there's an out-of-the-box solution for this requirement, but I can come up with (an ugly :)) workaround.
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.
You can do the following:
- Define a custom build variable, call it
task.A.status
and set tosuccess
- Create another build task, e.g.
C
and schedule it right afterA
; condition it to only run ifA
fails - there's a standard condition for that - The task
C
should only do one thing - settask.A.status
build variable to 'failure' (like this, if we are talking PowerShell:Write-Host "##vso[task.setvariable variable=task.A.status]failure"
) - Finally, the task
B
is scheduled sometime afterC
and is conditioned to run in casetask.A.status
equalsfailure
, like this:eq(variables['task.A.status'], 'failure')
I might be incorrect in syntax details, but you should get the general idea. Hope it helps.
来源:https://stackoverflow.com/questions/50351769/tfs-build-custom-conditions-for-running-a-task-check-if-specific-previous-task