问题
Is it possible to cancel a currently running build via REST API?
I've got an integration which fetches currently running builds, and I would like to terminate builds of a given type if they are failed. I know how to list the failing builds of a given type, how do I then pass the stop command?
回答1:
Maybe not with the REST API, but if you look here (towards the bottom in the Comments section) there's an 'undocumented' feature that lets you do it over HTTP.
回答2:
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 to cancel the current build 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
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.
"comment=..." can be set to describe why you're cancelling.
回答3:
Not exactly the REST call you were looking for, but you can simply do an HTTP POST to:
http://teamcity.my.org/viewLog.html?buildTypeId=bt278&buildId=1352480#
Where:
buildTypeId is your project's id
buildId is the build number to stop
Obviously, you can only do this while the build is running.
回答4:
Since TeamCity 8.1 it is possible to stop build using REST API:
curl -v -u user:password --request POST "http://localhost:7000/app/rest/buildQueue/<buildLocator>" --data "<buildCancelRequest comment='' readdIntoQueue='true' />" --header "Content-Type: application/xml"
来源:https://stackoverflow.com/questions/15827055/stop-a-teamcity-build-via-rest-call