TFS 为运行任务构建自定义条件 - 检查特定的先前任务是否失败 [英] TFS build custom conditions for running a task - check if specific previous task has failed
问题描述
TFS 构建允许指定运行任务的条件:参考.
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.
这类似于Only when a previous task 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?
推荐答案
似乎没有针对此要求的现成解决方案,但我可以想出(一个丑陋的 :))解决方法.
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.
假设您的特定任务(您检查其状态的任务)称为 A
.目标是仅在 A
失败的情况下调用另一个构建任务(比方说 B
).
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
并设置为success
- 创建另一个构建任务,例如
C
并在A
之后安排它;将它设置为仅在A
失败时运行 - 有一个标准条件 - 任务
C
应该只做一件事 - 将task.A.status
构建变量设置为失败"(就像这样,如果我们正在谈论 PowerShell:Write-Host "##vso[task.setvariable variable=task.A.status]failure"
) - 最后,任务
B
被安排在C
和 有条件运行,以防task.A.status
等于failure
,像这样:eq(variables['task.A.status'], 'failure')
- 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.
这篇关于TFS 为运行任务构建自定义条件 - 检查特定的先前任务是否失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!