Tue 1 Nov 2011
What’s In A Build Number?
Recently I blogged about our approach to using executable jar/war files for deployment. As part of this we came up with an interesting method of handling build numbers. We did not want to be restricted by things like incremental numbers since they can get weird if you branch (which for this app we do not). What we decided to do was to use a combination of the git SHA and the date. The SHA is sufficient for telling us the head of the repository for a specific build. The date portion just makes it more human readable with the additional ability of being able to group builds by day. Below is the ruby code we use within buildr to calculate our version number:
require 'date'
def calculate_version_name
date_string = Date.today.strftime("%G.%m.%d")
sha = `git log -n 1 --pretty=format:'%h'`
"#{date_string}-#{sha}"
end
This ends up producing a build number that looks something like this – 2011.10.25-836ab79
The only drawback we’ve seen from this approach is that the build numbers cannot be easily sorted chronologically, but so far we haven’t needed that.
What do people think?

If you have a list of all build numbers and alphabetically sort them doesn’t that get you chronological ordering?
Not if you have multiple builds per day, which we do. So far we haven’t needed to do this. I’ll try to post a follow up article around how we determine the latest successful build.
We found that just using the date and the sha didn’t really give enough information to be useful if visually inspecting the build number. Usually one only cares about this if deploying something other than the lastSuccessfulBuild or when looking for data in Jenkins given a build number (did my change make it into this build?).
We chose to add the timestamp and Jenkins build number to the war file build number for the new analytics 2.0 applications. This way, we can tell the ordering of builds from the build number and have everything we need to correlate it both to Git and Jenkins. These build numbers look like:
224-2011.11.03T15.17-6c985a9
Where 224 is the Jenkins build number.