API: cancelling running builds

Answered

I'm trying to cancel a running build via the API. When I POST, as instructed by the docs, I get a 405 response with this content:

Error has occurred during request processing (405).\nError: javax.ws.rs.WebApplicationException\nNot supported request. Please check URL, HTTP method and transfered data are correct. metadata: [Allow:[GET,DELETE,OPTIONS,HEAD],]

This tells me that POST is not supported. And the build is not cancelled.

Since I saw DELETE in the list of supported methods, I tried that. DELETE does cancel the build, but returns a 400 with this message:

Error has occurred during request processing (Bad Request).\nError: jetbrains.buildServer.server.rest.errors.BadRequestException: Deleting not finished builds is not supported. Cancel the build and only then delete it.\nInvalid request. Please check the request URL and data are correct.

Am I doing it wrong?

 

0
7 comments

Hello,

Could you please post the example of the POST request that you used?

0
Avatar
Permanently deleted user

I reworked it as a curl using the example from the docs:

>>> curl -v -u "robot:<pass>" --request POST "http://<host>:8111/app/rest/builds?locator=id:8962" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"
...
>
* upload completely sent off: 56 out of 56 bytes
< HTTP/1.1 405 Method Not Allowed
< Server: Apache-Coyote/1.1
< Set-Cookie: TCSESSIONID=79BFB69ED33B151551CC8B9391D25D5E; Path=/; HttpOnly
< Set-Cookie: RememberMe=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/; HttpOnly
< Pragma: no-cache
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Cache-Control: no-cache
< Cache-Control: no-store
< Content-Type: text/plain
< Transfer-Encoding: chunked
< Date: Thu, 28 Apr 2016 13:51:55 GMT
<
Error has occurred during request processing (405).
Error: javax.ws.rs.WebApplicationException
* Connection #0 to host e0264.test.urbanairship.com left intact
Not supported request. Please check URL, HTTP method and transfered data are correct. metadata: [Allow:[GET,DELETE,OPTIONS,HEAD],]%

 

0

The URL with "?locator" returns the list of builds. POST requests are only supported for a specific build, for example:

http://<host>:8111/app/rest/builds/id:8962
0
Avatar
Permanently deleted user

That worked! I could have sworn I tried that, but I must have messed it up some other way. Thank you!

0
Avatar
Permanently deleted user

Hi there Alina Mishina! I found this thread because I'm attempting to use the TeamCity rest API to fail a build after it has finished running. 

Right now, I'm getting the following response:

"Responding with error, status code: 400 (Bad Request). Details: jetbrains.buildServer.server.rest.errors.BadRequestException: Cannot cancel finished build Invalid request. Please check the request URL and data are correct."

If one can manually mark a build as failed from the UI after it has finished, I don't know why the API would restrict this behavior. But based on the response above, I'm not sure if what I'm attempting is possible. Either way, I'd like to be certain. 

Thanks so much in advance for any help you or someone on the Jetbrains team can provide!

0

Hi, your issue is actually not linked to this one. It's answered in the following one instead.

 

https://teamcity-support.jetbrains.com/hc/en-us/community/posts/206165169-Is-it-possible-to-mark-a-build-as-failed-via-a-REST-call-to-teamcity-you-can-view-the-status-but-can-you-change-it-

 

There is an experimental feature to fail a build described in the last comments in the issue in the tracker: https://youtrack.jetbrains.com/issue/TW-38093

0
Avatar
Permanently deleted user

This is helpful, thank you Denis Lapuente!

0

Please sign in to leave a comment.