VSTS - 有没有办法只在特定任务失败时运行任务? [英] VSTS - Is there a way to only run a task if a specific task has failed?
问题描述
我需要在我的构建定义中运行发布任务,但前提是某个任务失败之前.如果其他任务通过,我希望它被忽略而不运行.
有没有办法做到这一点?
我希望我可以根据任务成功设置一个输出变量,然后在自定义条件中使用该变量在任务失败时运行该任务.
如果任务失败,我看不到如何设置输出变量.这可能吗?
- 在任务设置中展开控制选项"
- 在运行此任务"中选择 -
仅当前一个任务失败时
.
如果您只想在最后/特定任务失败时运行任务:
假设您的特定任务(您检查其状态的任务)称为 A
.目标是仅在 A
失败的情况下调用另一个构建任务(比方说 B
).
- 定义一个
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?
解决方案- In the Task settings expand the "Control Options"
- Choose in "Run this task" -
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 sayB
) only in caseA
fails.- 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')
这篇关于VSTS - 有没有办法只在特定任务失败时运行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!