Fair point. For someone (or me!) who is looking at this in the future, TeamCity sets a bunch of environment variables by itself, so the pre-build step can inspect to see if the environment variable exists or not, and use that. TeamCity sets BUILD_NUMBER to the build number as well as other variables that may be useful such as the commit hash, project name, etc. To see what is available, have the build server send “set” so the log will contain all the environment variables.