1
votes

I'm trying to create build configuration for a project in TeamCity 8.0 using REST API. However instead of creating a new configuration I want to copy from an existing build configuration template. Basically, I'm looking to implement before option present in TeamCity web interface:

TeamCity Build Configuration - Create from Template

TeamCity REST API documentation is not extensive and it does not provide any details about how to create build configuration using existing template via REST API. Any input on how this can be done using REST API ?

1

1 Answers

1
votes

I believe TC 8.x and TC 9.x REST APIs are pretty similar. This example was written for TC 9.x.

I don't know if you have sorted this out, but (for the record) you have to do what the "Create a new build configuration with all settings" says. Basically, you have to create an XML with a format like this:

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

And do a POST to this URL: http://TCServerName:Port/httpAuth/app/rest/buildTypes

That is the XML expected by TeamCity, so it's up to you in which programming language you will create it. I have done this with C#/LINQ to XML and worked just fine.

Hope this helps.