Can I cancel a TeamCity build from my msbuild script?

后端 未结 4 512
梦谈多话
梦谈多话 2021-01-11 16:51

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 ind

相关标签:
4条回答
  • 2021-01-11 17:06

    You can use the undocumented http request which has changed since it was originally posted. You now need "operationKind=1". I used a powershell runner like so:

    $buildId = %teamcity.build.id%
    $uri = "http://teamcity/ajax.html?guest=1&comment=Cancelling+build+for+some+reason&submit=Stop&buildId=$buildId&kill&operationKind=1"
    $response = Invoke-WebRequest -UseBasicParsing -Uri $uri
    

    Another SO post can tell you how to make an http request from MSBuild

    The "guest=1" means I'm using the guest account, which at minimum needs the "Stop build / remove from queue" for the project you're going to cancel.

    0 讨论(0)
  • 2021-01-11 17:08

    Can you not just use the Error task, this should cause the execution of the build to stop.

    0 讨论(0)
  • 2021-01-11 17:10

    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']
    
    0 讨论(0)
  • 2021-01-11 17:23

    Since Teamcity 8.1 (Source) it is possible to Cancel the Build via REST API.

    Taken from the 9.x Documentation, cancelling a currently running build

    curl -v -u user:password --request POST "http://teamcity:8111/app/rest/builds/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"
    
    0 讨论(0)
提交回复
热议问题