Invoke Rest API under build steps using powershell scripts and system properties username and password
Hi All,
I am trying to invoke team city rest api to get the build status under build steps using powershell Invoke-RestMethod and using system properties username and password like %system.teamcity.auth.userId% and %system.teamcity.auth.password. But I get error :
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
... BuildInfo = Invoke-RestMethod -Method Get -Uri 'https://TeamCityBuild ...
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest)
[Invoke-RestMethod], WebExc
eption
FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
However, if I try using "Authorization" with Bearer <Token> generated from my profile, it works fine. But the problem is I don't want to expose my token and would like to use system userid and password.
If some one has done something similar can you please help ?The code which I am trying to execute:
Invoke-RestMethod -Method Get -Uri 'https://"%system.teamcity.auth.userId%":"%system.teamcity.auth.password%"@<teamcityURL>/httpAuth/app/rest/builds/id:%teamcity.build.id%' -Headers @{'Accept' = 'application/json'}
Thanks
Keshri
Please sign in to leave a comment.
How did you resolve this?