Triggering a build using REST API and parameters

I have figured out how to trigger a build using the rest api (example below) and have figured out how to add parameters to a build project. However I cannot find an example of triggering a build via the rest api while passing in parameters.

This is what I am using to trigger a build using curl:

curl -X POST -u apiuser:apipassword  -d  '<build><buildType id="SpringPetclinic_Build"/></build>' http://localhost:8111/httpAuth/app/rest/buildQueue --header "Content-Type: application/xml" -H "Accept: application/json"

Do I pass the parameters as part of the POST data?

Thanks

5 comments
Comment actions Permalink

Figured it out, it's the Properties xml node:


curl -X POST -u apiuser:apipassword  -d  '<build><buildType id="SpringPetclinic_Build"/>

<properties><property
 
name="PARAM1"
 
value="VALUE1"/></properties>
</build>' http://localhost:8111/httpAuth/app/rest/buildQueue --header "Content-Type: application/xml" -H "Accept: application/json"
1
Comment actions Permalink

Hello.
I'm trying to trigger a build using rest api with parameters, but I haven't found the example with json.

Where I can find the example?

Thanks.

0
Comment actions Permalink

Hi

I'm also looking for a json example.

@W0lfheart, any luck?

Thanks.

0
Comment actions Permalink

The following JSON should work:

 

{"branchName":"branch_name","buildType":{"id":"Sample_Build_Config_ID","projectId":"Sample_Project_ID"},"properties":{"property":[{"name":"property_name","value":"property_value"}]}}

 

Where the parameters would be in the properties array.

 

1
Comment actions Permalink

Thanks all.

Indeed it looks more neat with JSON parameters body from comment by Denis Lapuente

The whole command I used:

[UPD]: added json property for build comment

curl -k -n -X POST -d '{"buildType":{"id":"Sample_Build_Config_ID","projectId":"Sample_Project_ID"},"comment":{"text":"test comment"},"properties":{"property":[{"name":"property_name","value":"property_value"}]}}' https://your-teamcity-address/httpAuth/app/rest/buildQueue --header "Content-Type: application/json" -H "Accept: application/json"

-k lets overcome the certificate issues we have internally

-n let's you keep credentials in _netrc (windows) / .netrc (linux)file in home folder (see this)

1

Please sign in to leave a comment.