Is there a system/environment variable for the current build id?

In TeamCity build configuration we have access to all kinds of properties of the build via the %propertyname% syntax. For example, %env.BUILD_NUMBER%.
But one seems to be missing, and that is a property for the current build id. That is, the unique identifier assigned to every build. It's what the TeamCity REST api calls the "internal build id". Not to be confused with the BUILD_NUMBER (which is more like a label), nor the "build type id" (which is the unique id assigned to the build configuration).  

How can I get access to the internal build id of the currently running build, and the internal build ids of dependent builds?


We added this feature in TC 6.0. In 5.1 there is no such property and we do not have plans to add it. BTW, what's bad with build number? I guess it should work well until you have duplicate build numbers.


I noticed some funkiness in my teamcity build properties file (attached).  It appears the line for the TeamCityBuildId property is running up onto the previous line.  Here's an excerpt:




Is that right, or is there a bug here?  It would explain why I can't find the build id.


Exactly as you state, we have duplicate build numbers*.  Our build numbers look like this: 3.1.2.{build.vcs.number}.  We have separate debug and release build configs so we get dups between them.  And personal builds or user launched builds (basically any build without an svn change) causes dups within a build configuration.

But maybe I can work around all that stuff.  Which leaves me with the problem of accessing the REST api using only a build type id and a build number.  Can you help me form the proper <buildLocator> using these values?

Say I have this link that works and fetches build id 400:

What would the url look like if said build id corresponded to build number and build type id 104?


* As an aside, it strikes me as odd that the REST api explicitly calls out build ids, but then you don't expose that value.  What's an api consumer to do?


This is a valid value of "teamcity.auth.userId" property. It does include the buildId, but it is not meant to be used (and can change in future verisons of TeamCity).

For a reference, the original issue that you arose is filed as TW-4296.


Please sign in to leave a comment.