VSTS-有没有一种方法可以仅在特定任务失败时才运行任务? [英] VSTS - Is there a way to only run a task if a specific task has failed?
问题描述
我需要在我的构建定义中运行一个发布任务,但前提是某个任务失败之前.如果其他任务通过了,我希望忽略它并且不运行.
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?
推荐答案
- 在任务"设置中,展开控制选项"
- 选择运行此任务"-
Only when a previous task has failed
. - In the Task settings expand the "Control Options"
- Choose in "Run this task" -
Only when a previous task has failed
. - 定义自定义生成变量,将其命名为
task.A.status
并设置为success
- 创建另一个构建任务,例如
C
并将其安排在A
之后;使其仅在A
失败的情况下才能运行-有一个标准条件 - 任务
C
应该只做一件事-将task.A.status
构建变量设置为'failure'(如果正在使用PowerShell:Write-Host "##vso[task.setvariable variable=task.A.status]failure"
,则将其设置为"failure") - 最后,任务
B
被安排在C
和 - 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')
如果仅在上一个/特定任务失败时才运行任务:
假设您的特定任务(就其状态而言,您检查过的任务)称为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.
这篇关于VSTS-有没有一种方法可以仅在特定任务失败时才运行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!