ibrikin
1/18/2016 - 1:18 PM

TeamCity REST API Commands

TeamCity REST API Commands

Projects

Create a Project

URL: http://teamcity:8111/httpAuth/app/rest/projects/

Method: POST

Accept: application/xml

Example:

 curl -u admin:password \
      -X POST \
      -d 'test-project1' \
      -H 'Content-Type: text/plain' \
      http://teamcity:8111/httpAuth/app/rest/projects/

Response:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <project id="TestProject1"
          name="test-project1"
          href="/httpAuth/app/rest/projects/id:TestProject1"
          description=""
          archived="false"
          webUrl="http://teamcity:8111/project.html?projectId=TestProject1">
     <parentProject id="_Root"
                    name="&lt;Root project&gt;"
                    href="/httpAuth/app/rest/projects/id:_Root"/>
     <buildTypes/>
     <templates/>
     <parameters/>
     <vcsRoots href="/httpAuth/app/rest/vcs-roots?locator=project:(id:TestProject1)"/>
     <projects/>
 </project>

Delete a project

URL: http://teamcity:8111/httpAuth/app/rest/projects/${projectId}

Method: POST

Accept: application/xml

Example:

 curl -u admin:password \
      -X DELETE http://teamcity:8111/httpAuth/app/rest/projects/test-project1

Response:

None.

VCS roots

Create a Perforce VCS root

URL: http://teamcity:8111/httpAuth/app/rest/vcs-roots/${vcsId}

Method: POST Accept:

Example:

vcs-root.xml:

 <vcs-root id="TestProject1-perforce"
           name="test-project1-perforce"
           vcsName="perforce"
           shared="false"
           status="FINISHED"
           lastChecked="20130808T182940+0100">
     <project id="TestProject1"
              name="test-project1"
              href="/httpAuth/app/rest/projects/id:TestProject1"/>
     <properties>
         <property name="client-mapping" value="//path/to/project/... //team-city-agent/..."/>
         <property name="p4-exe" value="p4"/>
         <property name="port" value="perforce:1666"/>
         <property name="use-client" value="false"/>
         <property name="use-login" value="true"/>
         <property name="workspace-options"
                   value="Options: noallwrite noclobber nocompress unlocked nomodtime normdir SubmitOptions: revertunchanged LineEnd: local"/>
     </properties>
 </vcs-root>

Command-line:

 curl -u admin:password \
      -H "Content-Type: application/xml" \
      -d @vcs-root.xml \
      -X POST \
      http://teamcity:8111/httpAuth/app/rest/vcs-roots/

Response:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <vcs-root id="TestProject1_TestProject1perforce"
           name="test-project1-perforce"
           vcsName="perforce"
           status="NOT_MONITORED"
           lastChecked="20130930T111335+0100"
           href="/httpAuth/app/rest/vcs-roots/id:TestProject1_TestProject1perforce">
 <project id="TestProject1" name="test-project1"
          href="/httpAuth/app/rest/projects/id:TestProject1"/>
     <properties>
         <property name="client-mapping" value="//path/to/project/... //team-city-agent/..."/>
         <property name="p4-exe" value="p4"/>
         <property name="port" value="perforce:1666"/>
         <property name="use-client" value="false"/>
         <property name="use-login" value="true"/>
         <property name="workspace-options"
                   value="Options: noallwrite noclobber nocompress unlocked nomodtime normdir SubmitOptions: revertunchanged LineEnd: local"/>
     </properties>
     <vcsRootInstances href="/httpAuth/app/rest/vcs-root-instances?locator=vcsRoot:(id:TestProject1_TestProject1perforce)"/>
 </vcs-root>

Update a Perforce VCS root's URL

URL: http://teamcity:8111/httpAuth/app/rest/vcs-roots/${vcsRootId}/properties/client-mapping

Method: PUT

Accept:

Example:

Get VCS roots

URL: http://teamcity:8111/httpAuth/app/rest/vcs-roots

Method: GET

Content-Type: application/xml

Example:

 curl -u admin:password -X GET http://teamcity:8111/httpAuth/app/rest/vcs-roots

Response:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <vcs-roots count="1">
     <vcs-root id="TestProject1_TestProject1perforce"
               name="test-project1-perforce"
               href="/httpAuth/app/rest/vcs-roots/id:TestProject1_TestProject1perforce"/>
 </vcs-roots>

Get VCS root

URL: http://teamcity:8111/httpAuth/app/rest/vcs-roots/${vcsId}

Method: GET

Content-Type: application/xml

Example:

 curl -u admin:password -X GET http://localhost:8111/httpAuth/app/rest/projects/TestProject1

Response:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <project id="TestProject1"
          name="test-project1"
          href="/httpAuth/app/rest/projects/id:TestProject1"
          description=""
          archived="false"
          webUrl="http://teamcity:8111/project.html?projectId=TestProject1">
     <parentProject id="_Root" 
                    name="&lt;Root project&gt;"
                    href="/httpAuth/app/rest/projects/id:_Root"/>
     <buildTypes/>
     <templates/>
     <parameters/>
     <vcsRoots href="/httpAuth/app/rest/vcs-roots?locator=project:(id:TestProject1)"/>
     <projects/>
 </project>

Attach VCS root to build configuration

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/vcs-root-entries

Method: POST

Accept: application/xml

Example:

vcs-roots.xml:

 <vcs-root-entry id="TestProject1_TestProject1perforce">
     <vcs-root id="TestProject1_TestProject1perforce"
               name="test-project1-perforce"
               href="/httpAuth/app/rest/vcs-roots/id:TestProject1_TestProject1perforce"/>
     <checkout-rules/>
 </vcs-root-entry>

Command-line:

 curl -u admin:password -H "Content-Type: application/xml" \
      -d @vcs-roots.xml \
      -X POST http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject1_Package/vcs-root-entries

Response

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <vcs-root-entry id="TestProject1_TestProject1perforce">
     <vcs-root id="TestProject1_TestProject1perforce"
               name="test-project1-perforce"
               href="/httpAuth/app/rest/vcs-roots/id:TestProject1_TestProject1perforce"/>
     <checkout-rules></checkout-rules>
 </vcs-root-entry>

Update the URL of a Perforce VCS root

URL: http://teamcity:8111/httpAuth/rest/vcs-roots/${vcsRootId}/properties/client-mapping

Method: PUT

Accept: application/xml

Content-type: text/plain

Example:

Command-line:

 curl -u admin:password \
      -X PUT \
      -d '//another/path/to/project/... //team-city-agent/...' \
      -H 'Content-Type: text/plain' \
      http://teamcity:8111/httpAuth/app/rest/vcs-roots/TestProject1_TestProject1perforce/properties/client-mapping

Response:

 //another/path/to/project/... //team-city-agent/...

Delete VCS root

URL: http://teamcity:8111/httpAuth/app/rest/vcs-roots/${vcsId}

Method: DELETE

Example:

 curl -u admin:password \
      -X DELETE \
      http://teamcity:8111/httpAuth/app/rest/vcs-roots/TestProject1_TestProject1perforce

Response:

None.

Build Types

Create Buid Type

URL: http://teamcity:8111/httpAuth/app/rest/projects/${projectId}/buildTypes/

Method: POST

Accept: application/xml

Content-type: text/plain

Example:

curl -u admin:password \
     -X POST \
     -d 'package' \
     -H 'Content-Type: text/plain' \
     http://teamcity:8111/httpAuth/app/rest/projects/TestProject1/buildTypes/

Response:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<buildType id="TestProject1_Package"
           name="package"
           href="/httpAuth/app/rest/buildTypes/id:TestProject1_Package"
           webUrl="http://teamcity:8111/viewType.html?buildTypeId=TestProject1_Package"
           paused="false">
    <project id="TestProject1"
             name="test-project1"
             href="/httpAuth/app/rest/projects/id:TestProject1"/>
    <builds href="/httpAuth/app/rest/buildTypes/id:TestProject1_Package/builds/"/>
    <vcs-root-entries/>
    <settings>
        <property name="allowExternalStatus" value="false"/>
        <property name="artifactRules"/>
        <property name="buildNumberCounter" value="1"/>
        <property name="buildNumberPattern" value="%build.counter%"/>
        <property name="checkoutDirectory"/>
        <property name="checkoutMode" value="ON_SERVER"/>
        <property name="cleanBuild" value="false"/>
        <property name="enableHangingBuildsDetection" value="true"/>
        <property name="executionTimeoutMin" value="0"/>
        <property name="maximumNumberOfBuilds" value="0"/>
        <property name="shouldFailBuildIfTestsFailed" value="true"/>
        <property name="shouldFailBuildOnAnyErrorMessage" value="false"/>
        <property name="shouldFailBuildOnBadExitCode" value="true"/>
        <property name="shouldFailBuildOnOOMEOrCrash" value="true"/>
        <property name="showDependenciesChanges" value="false"/>
        <property name="vcsLabelingBranchFilter" value="+:&lt;default&gt;"/>
    </settings>
    <parameters/>
    <steps/>
    <features/>
    <triggers/>
    <snapshot-dependencies/>
    <artifact-dependencies/>
    <agent-requirements/>
</buildType>

Set a Build Type Property

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/settings/${settingName}

Method: PUT

Content-type: text/plain

Example:

 curl -u admin:password -H "Content-Type: text/plain" \
      -d 'false' \
      -X PUT \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject1_Package/settings/cleanBuild

Response

None.

Set Artifact Rules

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/settings/artifactRules

Method: PUT

Content-type: text/plain

Example:

 curl -u admin:password -H "Content-Type: text/plain" \
      -d 'target/foo-project.tar.gz' \
      -X PUT \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject1_Package/settings/artifactRules

Response

None.

Build Steps

Create a Maven Build Step

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/steps

Method: POST

Content-type: application/xml

Accept: application/xml

Example:

build-step-maven.xml:

 <step id="RUNNER_1" name="package" type="Maven2">
     <properties>
         <property name="goals" value="clean package"/>
         <property name="mavenSelection" value="mavenSelection:default"/>
         <property name="teamcity.step.mode" value="default"/>
         <property name="userSettingsSelection" value="userSettingsSelection:default"/>
     </properties>
 </step>

Command-line:

 curl -u admin:password \
      -X POST \
      -d @build-step-maven.xml \
      -H 'Content-Type: application/xml' \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject1_Package/steps

Response

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <step id="RUNNER_1" name="package" type="Maven2">
     <properties>
         <property name="goals" value="clean package"/>
         <property name="mavenSelection" value="mavenSelection:default"/>
         <property name="teamcity.step.mode" value="default"/>
         <property name="userSettingsSelection" value="userSettingsSelection:default"/>
     </properties>
 </step>

Create a Command-line Build Step

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/steps

Method: POST

Content-type: application/xml

Accept: application/xml

Example:

build-step-cmdline.xml:

 <step id="RUNNER_12" name="run-it-tests" type="simpleRunner">
     <properties>
         <property name="script.content" value="echo 'Running integration tests...'"/>
         <property name="teamcity.step.mode" value="default"/>
         <property name="use.custom.script" value="true"/>
     </properties>
 </step>

Command-line:

 curl -u admin:password \
      -X POST \
      -d @build-step-cmdline.xml \
      -H 'Content-Type: application/xml' \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject1_Package/steps

Response

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <step id="RUNNER_8" name="run-it-tests" type="simpleRunner">
     <properties>
         <property name="script.content" value="echo 'Running integration tests...'"/>
         <property name="teamcity.step.mode" value="default"/>
         <property name="use.custom.script" value="true"/>
     </properties>
 </step>

Get the List of Steps for a Build Type

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/steps

Method: GET

Content-type: application/xml

Example:

 curl -u admin:password \
      -X GET \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject1_Package/steps

Response:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <steps>
     <step id="RUNNER_1" name="package" type="Maven2">
         <properties>
             <property name="goals" value="clean package"/>
             <property name="mavenSelection" value="mavenSelection:default"/>
             <property name="teamcity.step.mode" value="default"/>
             <property name="userSettingsSelection" value="userSettingsSelection:default"/>
         </properties>
     </step>
     <step id="RUNNER_8" name="run-it-tests" type="simpleRunner">
         <properties>
             <property name="script.content" value="echo 'Running integration tests...'"/>
             <property name="teamcity.step.mode" value="default"/>
             <property name="use.custom.script" value="true"/>
         </properties>
     </step>
 </steps>

Dependencies

Create an Artifact Dependency

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/artifact-dependencies

Method: POST

Content-type: application/xml

Accept: application/xml

Example:

artifact-dependency.xml:

 <artifact-dependency id="0" type="artifact_dependency">
     <properties>
         <property name="cleanDestinationDirectory" value="false"/>
         <property name="pathRules" value="foo-project.tar.gz"/>
         <property name="revisionName" value="lastSuccessful"/>
         <property name="revisionValue" value="latest.lastSuccessful"/>
     </properties>
     <source-buildType id="TestProject1_Package"
                       name="package"
                       href="/httpAuth/app/rest/buildTypes/id:TestProject1_Package"
                       projectName="test-project1"
                       projectId="TestProject1"
                       webUrl="http://teamcity:8111/viewType.html?buildTypeId=TestProject1_Package"/>
 </artifact-dependency>

Command-line:

 curl -u admin:password \
      -X POST \
      -d @artifact-dependency.xml \
      -H "Content-Type: application/xml" \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject2_Package/artifact-dependencies

Response:

The response is the same as the posted XML file.

Create a Snapshot Dependency

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/snapshot-dependencies

Method: POST

Content-type: application/xml

Accept: application/xml

Example:

snapshot-dependency.xml:

 <snapshot-dependency id="TestProject1_Package" type="snapshot_dependency">
     <properties>
         <property name="run-build-if-dependency-failed" value="false"/>
         <property name="run-build-on-the-same-agent" value="false"/>
         <property name="take-started-build-with-same-revisions" value="true"/>
         <property name="take-successful-builds-only" value="true"/>
     </properties>
     <source-buildType id="TestProject1_Package"
                       name="package"
                       href="/httpAuth/app/rest/buildTypes/id:TestProject1_Package"
                       projectName="test-project1"
                       projectId="TestProject1"
                       webUrl="http://teamcity:8111/viewType.html?buildTypeId=TestProject1_Package"/>
 </snapshot-dependency>

Command-line:

 curl -u admin:password \
      -X POST \
      -d @snapshot-dependency.xml \
      -H "Content-Type: application/xml" \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject2_Package/snapshot-dependencies

Response:

The response is the same as the posted XML file.

Delete an Artifact Dependency

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/artifact-dependencies

Method: DELETE

Example:

 curl -u admin:password \
      -X DELETE \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject2_Package/artifact-dependencies/0

Response:

None.

Delete a Snapshot Dependency

URL: http://teamcity:8111/httpAuth/app/rest/buildTypes/${buildTypeId}/snapshot-dependencies

Method: DELETE

Example:

 curl -u admin:password \
      -X DELETE \
      http://teamcity:8111/httpAuth/app/rest/buildTypes/TestProject2_Package/snapshot-dependencies/TestProject1_Package

Response:

None.