3

TeamCity has a list of Build Parameters, and it also knows the user that triggered a build; but I can't find that user name in the list of Build Parameters.

I would like to be able to send an email to the user that started a specific build without having to have that user set up a build notification through the TC UI, and in order to do that I would need to get the users name/email address from TC after a build is completed; but I can't see how I can pull that off. How can I get that users information from TC?

Charles
  • 50,943
  • 13
  • 104
  • 142
Russ
  • 12,312
  • 20
  • 59
  • 78

2 Answers2

1

use the REST api.

in your build script (whatever it is, powershell, nant, ruby, python) access the running build based on the buildID (which you get by querying teamcity.build.id)

http://servername:8080/httpAuth/app/rest/builds/id:289

in the returned result you can parse out the user id who triggered the build, then do another rest call

http://servername:8080/httpAuth/app/rest/users/id:3

in this result you can parse out the email address.

iwo
  • 405
  • 4
  • 13
  • Some comments: you can use the groovy plugin that adds some extra useful parameters to your build along with the trigger user name (or with some predefined string if it was an auto trigger). See http://confluence.jetbrains.com/display/TW/Groovy+plug – iwo Sep 14 '13 at 18:11
  • And this is also on their roadmap in Teamcity 8.1: http://youtrack.jetbrains.com/issue/TW-4502 – iwo Sep 14 '13 at 18:12
1

Actually you can do it with a single REST call:

http://servername:8080/httpAuth/app/rest/users/username:%teamcity.build.triggeredBy.username%

Where %teamcity.build.triggeredBy.username% is a TeamCity variable with the username of the user who triggered the build. As the name says.

Bruno Garcia
  • 6,029
  • 3
  • 25
  • 38