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

删除回忆录丶 提交于 2019-12-24 08:49:08

问题


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 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.



来源:https://stackoverflow.com/questions/50351769/tfs-build-custom-conditions-for-running-a-task-check-if-specific-previous-task

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!