Adding a Trigger to a build configuration in TeamCity using the REST API

旧时模样 提交于 2019-12-24 00:11:15

问题


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:


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);


来源:https://stackoverflow.com/questions/22996792/adding-a-trigger-to-a-build-configuration-in-teamcity-using-the-rest-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!