Teamcity REST API to programmatically change build queue order


Hi there


I am trying to programmaticaly change the build queue order using REST API

1. GET the build using locator

This returns an xml response containing various builds.


2. PUT call to REPLACE the build order

I rearrange the above xml response by interchanging few builds and while calling the below REST API

I pass the updated xml in the body.

However I am getting "The remote server returned an error: (405) Method Not Allowed."

Is there a working example of ReplaceBuilds method?

Comment actions Permalink


To replace build in queue:

  1. Get the list of queued builds using requests: http://localhost:8111/httpAuth/app/rest/buildQueue or http://localhost:8111/httpAuth/app/rest/builds/?locator=state:queued 
  2. Reorder builds in resulted xml file
  3. Put the resulted xml file (queuedBuilds.xml) using the following request:

    curl -u user:pass --request PUT http://teamcity/httpAuth/app/rest/buildQueue/ --data @queuedBuilds.xml --header "Content-Type: application/xml"

If it does not work for you, please provide the full request and response that you get. Also please note what TeamCity version is used.

Comment actions Permalink

Thanks a lot for your quick reply. I will try it out tomorrow and let you know.

I have few more questions related to this

1. Does the queuedBuilds.xml should be of format like below 


<?xml version="1.0" encoding="UTF-8" standalone="true"?>

-<builds count="1">

<build href="/httpAuth/app/rest/buildQueue/id:349" state="queued" buildTypeId="FeatureStreamA_F1bc2" id="349"/>



2. I have multiple projects and I would like to change the order only for builds within a given project. Build jobs in other projects should retain their order.

So in the PUT call how can I post to a specific URL which applies the order to a specific project?
Or can one specify the locator in the xml file as well?

Thanks in advance for your help.

Comment actions Permalink

For #1 I figured out that I had to use <?xml version="1.0" encoding="UTF-8" standalone="yes"?> 

ie standadlone  "yes" and not "true"

I couldnt find way to do #2. Will probably post a new topic to discuss.


Thanks for the help as I have few things working now.


Comment actions Permalink

The discussion continued in the following forum thread.


Please sign in to leave a comment.