server-only failure adding a build comment via the REST API

Answered

Hi folks,

 

I'm trying to add a build comment from within the currently running automated build script. I'm using the REST API: 

"https://teamcity.my-domain.com/app/rest/builds/id:{}/comment"

This script works perfectly on my workstation when run with the same build system credentials that are stored as secret passwords in TeamCity parameters.

I am confident that I'm getting the username and password correctly on the server because I have a log line showing the expected username in the log output.

[12:05:49]Adding a build comment with username: build_system

When the script runs as part of the build, the request is rejected by the server:
HTTPError: 401 Client Error: Unauthorized for url: https://teamcity.my-domain.com/app/rest/builds/id:{build_id}/comment

[12:05:49]Error information:
[12:05:49]401
[12:05:49]Incorrect username or password.
[12:05:49]To login manually go to "/login.html" page
0
1 comment
Avatar
Permanently deleted user

I was able to get this working by changing my calling code from Python's 'requests' basic auth to explicit basic auth headers with an encrypted token:

headers={
'cache-control': "no-cache",
'content-type': "text/plain",
'authorization': "Basic {}".format(os.environ.get('basicauth'))
})

 

0

Please sign in to leave a comment.