How to create a trigger using the REST API

I've also posted this question in StackOverflow so I apoligize for the duplication in case you've already seen it.

I'm trying to use TeamCity's REST API to create a new Build Configuration. To avoid doing everything manually I'm using TeamCitySharp.

I was able to create a build configuration, attach it to a template and even set parameters without major issues. But now I'm trying to setup build Triggers and TeamCitySharp requires the raw xml for the trigger configuration? Anyone could point me in the right direction here? Not sure where to start. I've looked over the REST API documentation on the JetBrains site but it doesn't go into the specifics.

An example using the plain REST API would be fine, it doesn't need to be using TeamCitySharp.

Thanks!

1 comment
Comment actions Permalink

Copied answer here:
------------------------------
I found the answer. I used Postman to do a GET on a BuildType that already had a Trigger configured:

http://teamcity:8111/httpAuth/app/rest/buildTypes/id20_mybuild

In the response you get the full config, including the XML for the Trigger. So, using TeamCitySharp, creating a trigger would look like this:
string xml = @"<trigger id=""TRIGGER_1"" type=""buildDependencyTrigger"">
                 <properties>
                    <property name=""dependsOn"" value=""id31_MyProject_SomeBuild""/>
                 </properties>
               </trigger>";

client.BuildConfigs.PostRawBuildTrigger(BuildTypeLocator.WithId("NewBuild"), xml);
0

Please sign in to leave a comment.