使用Authenticationn / Access令牌访问TeamCity时出现错误401未经授权

时间:2019-08-08 11:56:53

标签: powershell teamcity

尝试使用身份验证(JetBrains最近将其添加到TeamCity中的功能)访问TeamCity。该文档非常差,没有示例。只是对我不起作用。

执行PowerSHELL命令

以下不是我尝试的唯一方法,但作为示例,发布了调用诸如rest方法的命令:

GET

错误

出现以下错误:

$body="<build branchName=`"development`" rebuildAllDependencies=`"true`"><buildType id=`"DevSandbox_TestArea_PageAutomation`"/></build>"
Invoke-RestMethod -Uri http://teamcity.my.domain.com/httpAuth/app/rest/buildQueue/ -Method Post -ContentType application/xml -Body $body -Headers @{Origin= 'http://teamcity.my.domain.com'; Authorization= 'Bearer tEamCitYauThtoKen'} -UseBasicParsing

任何人都可以帮助我解决标题和/或缺少的内容吗?

更多参考资料

TeamCity 2019.1 Help - Managing Access Token

Powershell 6 - Invoke-RestMethod

1 个答案:

答案 0 :(得分:5)

仅当使用基本身份验证访问TeamCity服务器时,才需要URL中的/httpAuth/部分。

因此解决方案是使用网址http://teamcity.my.domain.com/app/rest/buildQueue/ 代替http://teamcity.my.domain.com/httpAuth/app/rest/buildQueue/ 因为您使用的是基于令牌的身份验证。