How to skip or execute tasks/steps conditionally using TFS build?
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.
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: