如何使用REST API从命令行触发TeamCity构建?

时间:2019-06-27 12:02:06

标签: command-line teamcity

我正在尝试从命令行触发TeamCity构建。 首先,我尝试过:

curl http://<user name>:<user password>@<server address>/httpAuth/action.html?add2Queue=<build configuration Id>

但是在最新版本的TeamCity中,此方法已删除,并且响应如下:

405此请求仅允许使用POST方法。

因此,基于来自https://www.jetbrains.com/help/teamcity/rest-api.html#RESTAPI-BuildRequests的信息,它应该以这种方式通过REST API运行:

url -v -u user:password http://teamcity.server.url:8111/app/rest/buildQueue --request POST --header "Content-Type:application/xml" --data-binary @build.xml

build.xml示例:

build.xml
<build>
    <buildType id="buildConfID"/>
</build>

对我来说,不清楚将配置的build.xml放在哪里?

1 个答案:

答案 0 :(得分:0)

curl -u user:password  -X POST \
  https://teamcity.host.io/app/rest/buildQueue \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/xml' \
  -H 'Host: teamcity.host.io' \
  -d '<build branchName="refs/heads/master">
  <triggeringOptions cleanSources="true" rebuildAllDependencies="false" queueAtTop="false"/>
  <buildType id="Test_Configuration_ID_for_trigger"/>
   <lastChanges>
    <change locator="version:e2418b4d7ae55ac4610dbff51bffe60d1f32e019"/>
  </lastChanges>
   <properties>
        <property name="env.startedBy" value="build was triggering from %teamcity.serverUrl%/viewLog.html?buildId=%teamcity.build.id%"/>
    </properties>

</build>'

您可以跳过lastChanges以根据最新更改运行构建