Mugen
Mugen

Reputation: 9095

TFS build custom conditions for running a task - check if specific previous task has failed

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?

Upvotes: 1

Views: 2542

Answers (1)

Yan Sklyarenko
Yan Sklyarenko

Reputation: 32270

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 to success
  • Create another build task, e.g. C and schedule it right after A; condition it to only run if A fails - there's a standard condition for that
  • The task C 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")
  • Finally, the task 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')

I might be incorrect in syntax details, but you should get the general idea. Hope it helps.

Upvotes: 2

Related Questions