Where are these environment variables coming from? Are they set by your continuous integration server?
Ant is simply grabbing environment variables. What I showed is the Gradle equivalent. There is no such thing as a “build number” in either Ant or Gradle. I expect something (Jenkins, TeamCity, etc) is injecting them into the environment.