Access Build Counter as an environment variable

Hi, I have overridden the Build Number (BUILD_NUMBER) format to be


however I still require access to the build counter {0} from my scripts.

How can I access this number as an environment variable?

I've tried addong an environment variable with and {0} as the value but neither of these gives the build counter number.

Can you make build counter a first-class environment variable instead of {0} or explain how to access it?

Comment actions Permalink


I can suggest an alternate approach: do not change build number format in configuration's settings, so both %BUILD_NUMBER% and %BUILD_VCS_NUMBER% variables have their original values. But replace it from the script using a service message.

Comment actions Permalink

Hi Michael,

Thanks for your reply, that helped. For those who come upon this thread this is what I did:

Background: In TeamCity I overrode BUILD_NUMBER from {0} to 2.0.{0} however this meant I couldnt use the 'raw' build number ({0}) in any of my scripts downstream.

To resolve this I:

1) Set Build Number Format in TeamCity back to {0}

2) Add as a environment varaible, env.ASS_PRODUCT, short for assembly product.

3) Emit this during the Visual Studio compile to update TeamCity to the 'real' build number. To do this I added this to the PreBuild event:
echo ##teamcity[buildNumber '%ASS_PRODUCT%']

You are now able to use the 'real' build number ('%ASS_PRODUCT%) or 'raw' build number (%BUILD_NUMBER%) in your scripts.

Comment actions Permalink

Thank you Wallace!


Please sign in to leave a comment.