1

I have a configuration parameter called "testing" in one of my build configurations in TeamCity. After taking a look at the TeamCity REST API doc here I could get information about this parameter using the following cURL command line commands on Windows:

(1) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters
(2) curl -X GET -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing

Response:

(1) <?xml version="1.0" encoding="UTF-8" standalone="yes"?><property name="testing" value="11"/></properties>
(2) 11

But then, when I try to update this "testing" build parameter using the following command, I get an error message:

curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing

Response:

Error has occurred during request processing (Unsupported Media Type).
Error: javax.ws.rs.WebApplicationException
Not supported request. Please check URL, HTTP method and transfered data are correct.

I already successfully use a similar command to update the buildNumberCounter setting of the same build configuration:

curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/settings/buildNumberCounter

That's why I thought I can do the same with a build parameter in a similar way. What am I missing here?

UPDATE:

I managed to update the "testing" build parameter with value "1" using Fiddler. The request I composed had the following content:

  • Request: PUT
  • URL: http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing
  • Request headers: Authorization: Basic (...)
  • Request body: 1

So the problem with my cURL command above is probably somewhere around the -d "1" option. But where?

UPDATE 2:

I'm not sure if that makes any difference, but I use this cURL build on Windows 7.

4 Answers 4

2

Instead of fixing the failing cURL command, as a workaround, we use now Node.js to compose and send the REST request to TeamCity.

The script that needs to be fed to node.exe is as follows:

// Equivalent cURL command:
// curl -X PUT -d "1" -H "Authorization: Basic (...)" http://teamcity:8080/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing

var http = require('http'),
    options = {
        hostname: 'teamcity',
        port: 8080,
        path: '/httpAuth/app/rest/buildTypes/id:bt7/parameters/testing',
        method: 'PUT',
        headers: { 'Authorization': 'Basic (...)' }
    },
    req;

req = http.request(options, function(res) { });

// write data to request body
req.write('1');
req.end();

Although the workaround works perfectly, I would still like to know what's wrong with the above cURL command?

Sign up to request clarification or add additional context in comments.

Comments

1

For parameters that are non-XML like the one you are asking about, just add: --Header "Content-Type: text/plain"

For parameters that are XML then you'll want to switch that to: --Header "Content-Type: application/xml"

Comments

1

I was having a hard time figuring this out too but I found the answer. Instead of using -d and -H at the front. Use --data and --header at the end as shown below . I found this in the TeamCity docs buried in a "click to expand" example.

Set build number counter:

curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberCounter --data <new number> --header "Content-Type: text/plain"

Set build number format:

curl -v --basic --user <username>:<password> --request PUT http://<teamcity.url>/app/rest/buildTypes/<buildTypeLocator>/settings/buildNumberPattern --data <new format> --header "Content-Type: text/plain"

Comments

0

I guess the REST API expect XML as input, add

-H "Content-type:text/xml"

and put XML as input. If you have a XML file file.xml :

curl -d "@/path/to/file.xml" -H "Content-type:text/xml" (...)

2 Comments

I found this in the TeamCity REST API doc: Build configuration parameters: GET/DELETE/PUT http://teamcity:8111/httpAuth/app/rest/buildTypes/<buildTypeLocator>/parameters/<parameter_name> (accepts/produces text/plain) And also see my update above, I managed to update the parameter with Fiddler without manually setting the content type to XML.
That quote actually essentially has the answer spelled out by specifying the content type that is required. You just need to put that into the header. See my answer below.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.