BLDNMBR is a quick way to get a unique build number for every build. To get an automatically incrementing build number just use the following:
http://bldnmbr.com/YOUR_UNIQUE_KEY
Just replace YOUR_UNIQUE_KEY with your key. The first number returned will be 0, each subsequent request to that URL will give you the next number.
Need to set your starting number to be your current build number? No problem!
http://bldnmbr.com/YOUR_UNIQUE_KEY?setBuildNumber=1337
This request will return 1338 and continue from there.
Need to give the current build number to multiple places or requests?
http://bldnmbr.com/YOUR_UNIQUE_KEY?currentBuildNumber
This request will return the current build number to every request without incrementing.
An example for an iOS project in XCODE. Add a build phase before "Compile Sources" and add the following
#!/bin/sh
echo "Build Number script config: ${CONFIGURATION}"
if [[ "${CONFIGURATION}" == "Release" || "${CONFIGURATION}" == "Ad-hoc" ]] ; then
echo "archive so setting build number"
baseVersion=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$PROJECT_NAME"/"$TARGET_NAME"-Info.plist`
buildNumber=$(/usr/bin/curl -s "http://bldnmbr.com/YOUR_UNIQUE_KEY.${baseVersion}")
#check to make sure that BLDNMBR gave us a number and not some non 200 response html
if [[ "$buildNumber" =~ ^[0-9]+$ ]] ; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$PROJECT_NAME"/"$TARGET_NAME"-Info.plist
else
echo "not an archive so not setting build number"
fi
fi
The above sample uses the version number as part of the key. This will reset the build number each time you increment your version number in your target.
There are some distirbution methods that do not support resetting your build number. Most of these systems are setup that way because of old Apple requirements. To make this work with those systems simply replace:
baseVersion=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$PROJECT_NAME"/"$TARGET_NAME"-Info.plist`
buildNumber=$(/usr/bin/curl -s "http://bldnmbr.com/YOUR_UNIQUE_KEY.${baseVersion}")
with:
buildNumber=$(/usr/bin/curl -s "http://bldnmbr.com/YOUR_UNIQUE_KEY")
A great site to help with adding a build phase
An example for an iOS project in XCODE and keep your git repo clean! I got this tip from the great article on using git commit count and branch name for your build number by Jared Sinclair. Add the following to a build phase after "Copy Bundle Resources".
#!/bin/sh
echo "Build Number script config: ${CONFIGURATION}"
if [[ "${CONFIGURATION}" == "Release" || "${CONFIGURATION}" == "Ad-hoc" ]] ; then
echo "archive so setting build number"
buildNumber=$(/usr/bin/curl -s "http://bldnmbr.com/YOUR_UNIQUE_KEY")
#check to make sure that BLDNMBR gave us a number and not some non 200 response html
if [[ "$buildNumber" =~ ^[0-9]+$ ]] ; then
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
else
echo "not an archive so not setting build number"
fi
fi
The above sample will not dirty your git repo as it changes the plist in the target directory. This sample will not reset your build number when you update your version number. To do that change the "buildnumber="" line to.
baseVersion=`/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"`
buildNumber=$(/usr/bin/curl -s "http://bldnmbr.com/YOUR_UNIQUE_KEY.${baseVersion}")
A great site to help with adding a build phase
BLDNMBR can be used for any build system that supports an http request. For instance if your build system supports running a shell script you can use:
/usr/bin/curl -s "http://bldnmbr.com/YOUR_UNIQUE_KEY
Just add code to store and use your shiny new build number in whatever way your build system needs it.