Cancel build when newer builds are pending
Answered
Hello,
Is it possible to cancel a running build when a newer build is triggered and that new build is pending? We have a build that takes around 5 minutes to complete, but at the moment this build is triggered again there is no use anymore in finishing the running build - we should start this build again. How can this be done?
Thanks,
Sander
Please sign in to leave a comment.
Hi,
you can cancel a build manually from the UI. The screens that show its progress should have a link to "Stop" which will stop the build in progress. You can also use it through the REST API. https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-BuildCanceling/Stopping
There is no automated way to stop a running build when a new instance of the same configuration is added to the queue. If you can get informed when a new build is added to the queue, you could then automatically stop the builds via the REST API as mentioned above.
To expand a bit on my previous message, we have 2 related requests in our tracker here:
https://youtrack.jetbrains.com/issue/TW-10905
https://youtrack.jetbrains.com/issue/TW-1858
There is also the possibility to implement a "watchdog", that will poll the server via the REST API for builds in the queue and then, as mentioned, cancel a running one when another of the same type is already in the queue.
If I were doing this (and I might soon have to) I would create a "preamble" job configuration that checks for running builds that are now obsolete by the new build request. If any are found those builds are cancelled.
The regular build job is now triggered when the "preamble" job completes.
The "preamble" job has the same triggers (changes found in VCS, etc.) that the regular job would normally have.
No, polling and no worries about concurrent jobs.
Hi,
i cant get the build to cancel by rest to work, the post request just returns nothing. a few things i tried:
curl -v -u user:pass --request POST "http://teamcity:8111/app/rest/builds/?buildId:11600711&buildTypeId=TSChainFast_ProjectWorkBuild_OrgProjectX64Release" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"
curl -v -u user:pass --request POST "http://teamcity:8111/app/rest/builds/?buildId:11600711" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"
curl -v -u user:pass --request POST "http://teamcity:8111/app/rest/builds/?locator=id:11600711" --data "<buildCancelRequest comment='' readdIntoQueue='false' />" --header "Content-Type: application/xml"
For a get request of:
http://teamcity/httpAuth/app/rest/builds/?locator=buildType:TSChainFast_ProjectWorkBuild_OrgProjectX64Release,running:any,canceled:any,count:2
i get
<builds count="2" href="/httpAuth/app/rest/builds/?locator=buildType:TSChainFast_ProjectWorkBuild_OrgProjectX64Release,running:any,canceled:any,count:2"nextHref="/httpAuth/app/rest/builds/?locator=buildType:TSChainFast_ProjectWorkBuild_OrgProjectX64Release,running:any,canceled:any,count:2,start:2">
<build id="11600711" buildTypeId="TSChainFast_ProjectWorkBuild_OrgProjectX64Release" number="35146" status="SUCCESS" state="running" running="true" percentageComplete="38"branchName="master" defaultBranch="true" href="/httpAuth/app/rest/builds/id:11600711" webUrl="http://teamcity/viewLog.html?buildId=11600711&buildTypeId=TSChainFast_ProjectWorkBuild_OrgProjectX64Release"/>
<build id="11600676" buildTypeId="TSChainFast_ProjectWorkBuild_OrgProjectX64Release" number="35145" status="UNKNOWN" state="finished" branchName="master" defaultBranch="true"href="/httpAuth/app/rest/builds/id:11600676" webUrl="http://teamcity/viewLog.html?buildId=11600676&buildTypeId=TSChainFast_ProjectWorkBuild_OrgProjectX64Release"/>
</builds>
can you give me a hand on this.
regards
jorge costa
Hi Jorge,
first, I assume it will be a typo, but please check that you are sending the post requests to :8111 while the get request is not.
Then, please remove the "?" from the request. simply app/rest/builds/id:<id> will do.
Could you give it a try?
yep, the ? did it. also app/rest/builds/<id> also works. thanks