Comment actions Permalink


You can perform it using REST API. You need to delete all canceled builds and then all canceled+personal:

DELETE http://teamcity:8111/httpAuth/app/rest/builds/canceled:true
DELETE http://teamcity:8111/httpAuth/app/rest/builds/canceled:true,personal:true

We also have a feature request - http://youtrack.jetbrains.com/issue/TW-8717, please watch and vote.

Comment actions Permalink

Hello Alina,

Thanks for your answer. I should have mentioned that I tried that before posting, but couldn't get it to work. Here is my problem: before performing the DELETE, I do a GET, to double check what's going to be deleted.

First, it looks like I have to use ?locator=... in the URL, otherwise I always get a single build, not a list:

But even then, I don't get all the expected builds. For instance, the following build is missing (accessed via https://teamcity/httpAuth/app/rest/builds/id:46306)

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <build id="46306" buildTypeId="BuildTypeId1"      number="N/A" status="UNKNOWN" state="finished" branchName="24/624/1"      href="/httpAuth/app/rest/builds/id:46306"      webUrl="https://teamcity/viewLog.html?buildId=46306&amp;buildTypeId=BuildTypeId1">      <statusText>Canceled</statusText>      <buildType id="BuildTypeId1" name="Prepare configuration"           description=""           projectName="Project" projectId="Project"           href="/httpAuth/app/rest/buildTypes/id:BuildTypeId1"           webUrl="https://teamcity/viewType.html?buildTypeId=BuildTypeId1" />      <tags />      <canceledInfo>           <user username="oc" name="Olivier Croquette" id="2"                href="/httpAuth/app/rest/users/id:21" />           <timestamp>20140626T085001+0200</timestamp>      </canceledInfo>      <queuedDate>20140624T154415+0200</queuedDate>      <startDate>20140624T154424+0200</startDate>      <finishDate>20140624T154424+0200</finishDate>      <triggered type="buildType" date="20140624T154415+0200">           <buildType id="BuildTypeId2" name="Run pre-merge tests"                description="Watches Gerrit changes and starts builds automatically"                projectName="Project" projectId="Project"                href="/httpAuth/app/rest/buildTypes/id:BuildTypeId2"                webUrl="https://teamcity/viewType.html?buildTypeId=BuildTypeId2" />      </triggered>      <lastChanges count="1">      </lastChanges>      <changes href="/httpAuth/app/rest/changes?locator=build:(id:46306)" />      <revisions>      </revisions>      <agent name="N/A" typeId="0" />      <artifacts href="/httpAuth/app/rest/builds/id:46306/artifacts/children" />      <relatedIssues href="/httpAuth/app/rest/builds/id:46306/relatedIssues" />      <statistics href="/httpAuth/app/rest/builds/id:46306/statistics" /> </build>

(sorry about the format. What's the proper way to insert XML code in a post ?)

Is it because it was never started ?
I actually want to delete all these builds that were canceled before they even started.


Comment actions Permalink

Hi Olivier,

Such request https://teamcity/httpAuth/app/rest/builds/?locator=canceled:true,personal:true returns builds which are canceled AND personal, and build that you posted is not personal. So firstly you need to delete all canceled builds and then canceled+personal. Such requests should also return all not started builds.

Comment actions Permalink

You are right, sorry for the confusion caused by my post, however I still have problems getting this to work.

First, some builds were still missing in my results (hence my confusion earlier). After some experimentation, I found out that there are some default filters, as per documentation:
Note: If build configuration utilizes feature branches then, by  default, only builds from default branch are returned. To retrieve all  builds, add the following locator: branch:default:any. The whole path  will look like this:  /httpAuth/app/rest/builds/?locator=buildType:One_Git,branch:default:any

So this is my request now:

The documentation is not entirely accurate from a user perspective, because I don't use feature branches, but rather remote run triggers with Gerrit.

Anyway, based on this, I tried:
DELETE httpAuth/app/rest/builds/personal:any,branch:default:any,canceled:true

and got this back:

  • Status Code: 204 No Content
  • Cache-Control: no-cache, no-store
  • Connection: Keep-Alive
  • Content-Length: 0
  • Date: Thu, 26 Jun 2014 08:45:33 GMT
  • Expires: Thu, 01 Jan 1970 00:00:00 GMT
  • Keep-Alive: timeout=5, max=100
  • Pragma: no-cache
  • Server: Apache-Coyote/1.1

  • I tried also:
    DELETE httpAuth/app/rest/builds/?locator=personal:any,branch:default:any,canceled:true

    But that doesn't work either:

    Status Code: 405 Method Not Allowed
      Cache-Control: no-cache, no-store
      Connection: Keep-Alive
      Content-Encoding: gzip
      Content-Type: text/plain
      Date: Thu, 26 Jun 2014 08:46:50 GMT
      Expires: Thu, 01 Jan 1970 00:00:00 GMT
      Keep-Alive: timeout=5, max=100
      Pragma: no-cache
      Server: Apache-Coyote/1.1
      Set-Cookie: ...
      Transfer-Encoding: chunked
      Vary: Accept-Encoding

      Any idea what I am doing wrong ?


      Comment actions Permalink

      The first DELETE request (without locator) which you send works correctly. It sends such response "204 No Content" after deleting a build.

      Comment actions Permalink

      OK, that's quite counter intuitive, but it actually deletes a build, thanks.

      So I am currently running this in a loop:

      read -s CRED
      for i in `seq 1 10100` ; do
        echo $i
        curl -u $CRED --insecure --request DELETE "https://teamcity/httpAuth/app/rest/builds/personal:any,branch:default:any,canceled:true"

      Since it takes about 1 sec per build, and I have about 10000 builds to delete, it will take a few hours.

      Is that currently the best way to do this ?
      If yes, I will open a feature request. This should be feasible in the web interface, or at least with a single REST command.

      Comment actions Permalink

      Now it's the only way to perform it. We have a feature request http://youtrack.jetbrains.com/issue/TW-8717, please watch and vote.

      Comment actions Permalink

      OK, thanks. I have voted for the mentioned issue, but also created another one to improve the REST API : http://youtrack.jetbrains.com/issue/TW-37080


      Please sign in to leave a comment.