How to fetch the branch and the build number directly from TeamCity?

I have a very large project that has lots of branches and multiple builds that are built continuously. What I want is to run my automation tests written in Go such that they first fetch the build number as well as the branch from TeamCity and then based on some validations run the tests accordingly.

I had tried giving a build number directly from inside my code, but that is a flawed approach as it isn't able to figure out the branch it needs to look at to find the build.

1 comment


How exactly do you start these tests? The values you are after are available as predefined build parameters build.number and Depending on how the tests are started, you could either pass them as startup parameters or read them from the environment variables. For the latter, you could define an environment variable that points to the branch parameter, for example:


The env.BUILD_NUMBER is available out of the box. 


Please sign in to leave a comment.