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
Please sign in to leave a comment.
Figured it out, it's the Properties xml node:
</build>' http://localhost:8111/httpAuth/app/rest/buildQueue --header "Content-Type: application/xml" -H "Accept: application/json"curl -X POST -u apiuser:apipassword -d '<build><buildType id="SpringPetclinic_Build"/>
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.
Hi
I'm also looking for a json example.
@W0lfheart, any luck?
Thanks.
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.
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)
How do I read the property value in the build step via command line shell script?
How can I find out all json fields which can be set on the request body, like branchName, and other possible fields?