【问题标题】:How to trigger TeamCity build from Command Line using REST API?如何使用 REST API 从命令行触发 TeamCity 构建?
【发布时间】:2019-11-09 10:42:42
【问题描述】:

我正在尝试从命令行触发 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 放在哪里?

【问题讨论】:

  • curl --data-binary 标志将文件名作为相对或绝对路径(参见 here ),因此它会在根目录中查找您的 build.xml 文件。您还可以按照this answer 执行--data-binary @path/to/file 来指定绝对路径

标签: command-line teamcity


【解决方案1】:
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 以在最新更改上运行构建

【讨论】:

    猜你喜欢
    • 2011-04-10
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多