How do I set the build number in Teamcity?
It seems the last line of the script should be:
Write-Host "##teamcity[buildNumber '${buildNumber}']"
A note: for the script to work, if should be specified as inline script in TeamCity build step (which makes TeamCity %-references to work).
BTW, you can make TeamCity display short branch name by using +:refs/heads/* branch specification in the VCS root
If you're using powershell the build number is available to your agents as an environmental variable, in powershell as:
$env:BUILD_NUMBER
This is number that you can configure thru the build configurations UI.