1

我正在尝试将构建配置附加到模板。我们正在运行 TeamCity 10.0.2,使用 PowerShell 4.0 与之交互。

根据TeamCity 10 API 文档,可以将构建附加到模板操作:

从/到模板读取、分离和附加构建配置:GET/DELETE/PUT http://teamcity:8111/app/rest/buildTypes/ /template(PUT 接受带有“text/plain” Content-Type 的模板定位器)

所以我试图将build12构建配置附加到template12模板中,我正在使用的代码如下

$webclient             = New-Object System.Net.WebClient
$creds                 = New-Object System.Net.NetworkCredential("user1","pass1")
$webclient.Credentials = $creds
$webclient.headers.Add("Content-Type", "text/plain") 
$webclient.UploadString("http://teamcity:8111/httpAuth/app/rest/buildTypes/build12/template", "PUT", "TemplateId")

但我不断收到以下错误:

Exception calling "UploadString" with "3" argument(s): "The remote server returned an error: (400) Bad Request."

有没有人能够通过 API 将构建配置附加到模板?

4

1 回答 1

0

我看到您使用 PowerShell,但您正在删除 C#WebClient类来执行此操作。不要那样做:)

Invoke-RestMethod http://teamcity/httpAuth/app/rest/buildTypes/YourBuildId/template -Credential $credential -Method Put -Headers @{"Content-Type"="text/plain"} -Body Your_Template

这会将模板附加Your_Template到您的构建中,称为YourBuildId

如果您需要有关-Credentials参数或其他任何内容的帮助,请告诉我。

我实际上已经使用上面的方法让它工作了......

于 2017-08-31T20:53:09.910 回答