如何使用 TFS 构建有条件地跳过或执行 tasks/steps?

How to skip or execute tasks/steps conditionally using TFS build?

我有一个 TFS 构建定义。

我希望 运行 两个 steps/task 有条件地执行两个命令行。也许我可以在排队构建或其他东西时设置一个变量。主要是我希望 运行 构建并跳过一些 steps/task 如果我愿意的话。我怎样才能做到这一点?除了制作一个执行我的 app.exe 的 bat 文件并将布尔变量发送到将执行或不执行我的 app.exe.

的 bat 脚本之外

更新 2017/04/19

您可以 specify conditions for running a task 在 VSTS 中。

To use this feature you must enable both the New Build Editor and the Task Conditions preview features for your account.


目前,这是不可能的。 UserVoice 中有一个 功能请求 并得到响应 STARTED

Allow build vNext/preview tasks to be conditionally enabled or disabled.

We have begun to work on this feature and it will be available on both team build and release management.

Team Services Group (Product group, Microsoft Visual Studio) responded · August 23, 2016

作为解决方法,您可以手动禁用构建任务(左键单击构建任务并 select 禁用 selected 任务 ) 如下截图:

通过在需要有条件执行的任务前添加一个PowerShell Script任务Write-Host "##vso[task.setvariable variable=ExecuteMyTask]$(ExecuteMyTask)",在其中添加一个名为ExecuteMyTask的新Process参数可以设置为 truefalse 的任务组(或留空,使用此任务组在构建定义中设置)。在'conditional'任务中可以添加自定义条件and(succeeded(), eq(variables['ExecuteMyTask'], 'true')),任务将有条件地执行。

这适用于 TFS.2018.2。