General writings of my software adventures and challenges. I often write for a place to store my own experiences for future search but can hopefully help others along the way

Xcode auto-increment build on archive

11 November 2014

Simple script to bump the build number of my Xcode project on each Archive. The version number I am leaving as a manual change for the moment, but each time I release a build to testers, I want the build to change and a commit message for the change. In Xcode from the menu go to Product -> Scheme -> Edit Scheme EditSchemeMenu On the side, expand the Arhive build and select Pre-actions. Here we will edit the pre-action script to increment the build number. Choose to provide the build settings from your main app target and in the script pane add:

BUILD_NUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")
VERSION_NUM=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")


/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILD_NUM" "${PROJECT_DIR}/${INFOPLIST_FILE}"

cd "${SRCROOT}";/usr/bin/git add "${PROJECT_DIR}/${INFOPLIST_FILE}"
cd "${SRCROOT}";/usr/bin/git commit -m "Post archive bumped build number to ${BUILD_NUM} for version ${VERSION_NUM}"
cd "${SRCROOT}";/usr/bin/git tag -f -a "v${VERSION_NUM}b${BUILD_NUM}" -m "Version ${VERSION_NUM}, Buidl ${BUILD_NUM}"

The Run Script pane will look like this afterwards: IncrementScriptEditing I also have another configuration for App Store release which you could then apply this same script except change the CFBundleShortVersionString to increment the version number