【问题标题】:Create build configuration from existing template in TeamCity using REST API使用 REST API 从 TeamCity 中的现有模板创建构建配置
【发布时间】:2015-08-11 22:06:04
【问题描述】:

我正在尝试使用 REST API 在 TeamCity 8.0 中为项目创建构建配置。但是,我不想创建新配置,而是想从现有的构建配置模板中复制。基本上,我希望在 TeamCity Web 界面中出现选项之前实现:

TeamCity REST API 文档并不详尽,也没有提供有关如何通过 REST API 使用现有模板创建构建配置的任何详细信息。关于如何使用 REST API 完成此操作的任何输入?

【问题讨论】:

    标签: rest teamcity-8.0 buildconfiguration


    【解决方案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>
    

    然后对这个 URL 做一个 POST:http://TCServerName:Port/httpAuth/app/rest/buildTypes

    这是 TeamCity 所期望的 XML,因此由您决定使用哪种编程语言创建它。我已经使用 C#/LINQ to XML 完成了这项工作,并且工作得很好。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      • 1970-01-01
      • 2014-06-23
      • 1970-01-01
      相关资源
      最近更新 更多