2015-05-29 100 views
1

我试图使用REST API在TeamCity 8.0中为项目创建构建配置。然而,我不想创建一个新的配置,而是想从现有的构建配置模板中复制。基本上,我正在寻找存在于TeamCity的web界面选项前实施:使用REST API从TeamCity中的现有模板创建构建配置

TeamCity Build Configuration - Create from Template

TeamCity的REST API文档并不广泛,它不提供有关如何使用通过REST现有的模板来创建构建配置的任何细节API。有关如何使用REST API完成此任何输入?

回答

1

我相信TC 8.x和TC 9.x REST API非常相似。这个例子是为TC 9.x编写的。

我不知道你是否对此进行了整理,但(对于记录),你必须执行“创建具有所有设置的新构建配置”。基本上,你必须创建这样一个格式的XML:

<buildType id="YourBuildID" name="YourBuildName" projectId="TheProjectIDThatOwnsThis" > 
    <project id="TheProjectIDThatOwnsThis" name="TheProjectName" parentProjectId="TheProjectParent" href="TheProjectHREFValue" webUrl="TheWebURLOfTheProejct" 
    /> 
    <template id="TemplateID" name="TemplateName" templateFlag="true" projectName="ProjectThatHasTheTemplate" projectId="ProjectThatHasTheTemplate" href="TemplateHRef" /> 
    <vcs-root-entries> 
     <!--vcs-root-entry elements are not necessary--> 
    </vcs-root-entries> 
    <settings>   
    </settings> 
    <parameters> 
    </parameters> 
    <steps> 
    </steps> 
    <features> 
    </features> 
    <triggers> 
    </triggers> 
    <snapshot-dependencies/> 
    <artifact-dependencies/> 
    <agent-requirements/> 
    <builds href="BuildConfigurationHREF" /> 
</buildType> 

,做一个POST到这个网址:http://TCServerName:Port/httpAuth/app/rest/buildTypes

由TeamCity的期望的XML,所以它是由你在编程你将创建它的语言。我已经用C#/ LINQ到XML来完成这个工作,并且工作得很好。

希望这会有所帮助。