Can I cancel a TeamCity build from my msbuild script?

msbuild, teamcity

Solution

According to JetBrains issue tracker and release page, since TeamCity 2019.1 EAP 1 builds can be stopped with service message as in:

##teamcity[buildStop comment='canceling comment' readdToQueue='true']

Problem

TeamCity allows me to report back from my MsBuild script using the ##teamcity interaction. I can use this to tell TeamCity that the build has FAILED, or indeed SUCCEEDED, however I would like to tell it to CANCEL the build instead. Does anyone know of a way to do this? I can use this to inform TeamCity of failure... ``` <Message Text="##teamcity[buildStatus status='FAILURE']" Condition="Something==SomeCondition" /> ``` I would love to do this... ``` <Message Text="##teamcity[buildStatus status='CANCEL']" Condition="Something==SomeCondition" /> ``` I've tried out the TeamCity Service Tasks but nothing thus far. EDIT: So it seems this feature is not available, although a workaround http request can be used to cancel a build. There is also a feature request for Cancelling a build the TC website.

Original source

Related problems