How to run a build step conditionally in TeamCity

It is not possible to execute build step based on condition. Vote for the related request: https://youtrack.jetbrains.com/issue/TW-17939.
The recommended approach is to create separate build configuration for each branch. You can use templates to simplify the setup. In this case it will be easier to interpret the results and the statistics of the builds will be informative.
Also see the related answer (hack is suggested).


JetBrains introduced support for conditional build steps in TeamCity 2020.1.

Here is a snippet of their blog post announcing this new feature:

Have you ever wanted to execute different command line scripts on different platforms, or deploy changes in different branches to different staging servers? Now you’re free to do just about anything! TeamCity 2020.1 allows you to specify conditions for your build steps and execute them only if the criteria are met.

conditional build steps demo