0

I have a Powershell script that I use to synchonize various projects parameters. The relevant code I use to update a project parameter is:

$propName = "ReleaseNumber"
$propValue = "10.0"
Invoke-RestMethod -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -Body "$propValue"

After the upgrade to TeamCity 9.1, I started receiving the following error when using the script:

Invoke-RestMethod : The remote server returned an error: (415) Unsupported Media Type.

What do I need to do to resolve this issue?

4

1 回答 1

6

默认情况下,ContentTypePowershell 发送的Invoke-RestMethodapplication/x-www-form-urlencoded. 在 TeamCity 9.1 之前,TeamCity 似乎不太关心ContentType与项目相关的 API 调用,但随着 9.1 以及XML 和 JSON 有效负载的添加,TeamCity 似乎对内容类型更加挑剔。因此,由于您的属性值只是纯文本,因此要解决问题,请指定text/plainContentType,如下所示:

Invoke-RestMethod -contentType "text/plain" -method Put -uri "$server/httpAuth/app/rest/projects/$targetProject/parameters/$propName" -body "$propValue"
于 2015-08-22T21:07:48.743 回答