Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
This is a script for incrementing build numbers in xcode, automatically during the build phase. It handles the build in the format xx.yy.zz where zz is incremented for each build, and yy is incremented when you archive your project. The xx is handled manually in this case. For more information, you can read my blog post at http://bit.ly/1h3ztJK
#!/bin/bash
conf=${CONFIGURATION}
arch=${ARCHS:0:4}
# Only increase the build number on Device and AdHoc/AppStore build
if [ $conf == "Release" ]
then
echo "Bumping bundle version number..."
buildPlist=${INFOPLIST_FILE}
bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.)(\d+)(\.\d+)/$1.($2+1).$3/eg'`
echo $bundleVersion;
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $bundleVersion" "$buildPlist"
echo "Bumping bundle short version number..."
bundleShortVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.)(\d+)/$1.($2+1)/eg'`
echo $bundleShortVersion;
/usr/libexec/PListBuddy -c "Set :CFBundleShortVersionString $bundleShortVersion" "$buildPlist"
else
echo "Bumping bundle version number..."
buildPlist=${INFOPLIST_FILE}
echo "${INFOPLIST_FILE}"
bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$buildPlist" | /usr/bin/perl -pe 's/(\d+\.\d+\.)(\d+)/$1.($2+1)/eg'`
echo $bundleVersion;
/usr/libexec/PListBuddy -c "Set :CFBundleVersion $bundleVersion" "$buildPlist"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment