Reputation: 1241
Trying to access TeamCity using the Authentication (feature which was added recently by JetBrains into TeamCity). The documentation is very poor with no example. It just doesn't work for me.
EXECUTING POWERSHELL COMMAND
Following is not the only way I tried, but as an example posting the command invoking a rest method like:
$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
ERROR
Getting the following error:
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:1 char:1
+ Invoke-RestMethod -Uri http://teamcity.my.domain.com/httpAuth/app/r ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Could anyone please help me what's wrong with the headers and/or anything that is missing?
FURTHER REFERENCE:
TeamCity 2019.1 Help - Managing Access Token
Powershell 6 - Invoke-RestMethod
Upvotes: 1
Views: 6052
Reputation: 163
The /httpAuth/
part in the url is only required when accessing the TeamCity server using Basic Authentication.
So the solution is to use the url http://teamcity.my.domain.com/app/rest/buildQueue/
instead of http://teamcity.my.domain.com/httpAuth/app/rest/buildQueue/
since you use Token-Based Authentication.
Upvotes: 10