TBogdan
TBogdan

Reputation: 737

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

I have a TFS build definition.

enter image description here

I wish to run two steps/task that execute two Command Lines, conditionally. Maybe with a variable I could set when I queue the build or something. Mainly I wish to run the build and skip some steps/task if I want to. How can I achieve this? Except making a bat file that executes my app.exe and sending a boolean variable to the bat script that will execute or not my app.exe.

Upvotes: 11

Views: 14941

Answers (2)

Emiel Koning
Emiel Koning

Reputation: 4225

By adding a PowerShell Script task with Write-Host "##vso[task.setvariable variable=ExecuteMyTask]$(ExecuteMyTask)" before the task that needs to be executed conditionally, a new Process parameter named ExecuteMyTask is added to the Task Group that can be set to true or false (or left empty, to be set in the Build definition using this Task Group). In the 'conditional' task a Custom Condition and(succeeded(), eq(variables['ExecuteMyTask'], 'true')) can be added and the task will be executed conditionally.

This works on TFS.2018.2.

Upvotes: 4

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51093

Update 2017/04/19

You could specify conditions for running a task in VSTS.

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


For now, it's impossible. There has been a feature request in UserVoice and get responded with 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

As a workaround, you could manually disable the build task (Left click the build task and select Disable selected tasks ) as follow screenshot: enter image description here

Upvotes: 14

Related Questions