11

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.

TBogdan
  • 737
  • 7
  • 17
  • 34

2 Answers2

14

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

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • 3
    It is now possibile with https://www.visualstudio.com/en-us/docs/build/concepts/process/conditions โ€“ Giulio Vian Apr 18 '17 at 11:39
  • With TFS 2017 Update 2, the conditional execution of tasks is possible but not when they are part of task groups. โ€“ Hamid Shahid Aug 11 '17 at 00:40
  • Up-to-date link to documentation (Azure DevOps = VSTS = TFS): https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml โ€“ Andrei Sinitson Apr 19 '21 at 04:01
4

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.

Emiel Koning
  • 4,039
  • 1
  • 16
  • 18