Skip to content

Xcode 6 Auto-Increment Build Number Script

Xcode 6 Auto-Increment Build Number Script

I recently started using Parse.com’ crash reporting and wanted to pay better attention to my build numbers in Xcode.

Xcode 6 Auto-Increment Build Number Script
Xcode 6 Auto-Increment Build Number Script

 

I found this post on stackoverflow about it and used the solution. It works great and I certainly want to give credit where it’s due.

 

 

Xcode 6 Auto-Increment Build Number

 

 

Steps:

1. Create a ‘tools’ directory in your project (where your xcodeproj or xcworkspace file is)

2. Create bump_build_number.sh in that directory and make this the contents…

#!/bin/sh

if [ $# -ne 1 ]; then
    echo usage: $0 plist-file
    exit 1
fi

plist="$1"
dir="$(dirname "$plist")"

# Only increment the build number if source files have changed
if [ -n "$(find "$dir" \! -path "*xcuserdata*" \! -path "*.git" -newer "$plist")" ]; then
    buildnum=$(/usr/libexec/Plistbuddy -c "Print CFBundleVersion" "$plist")
    if [ -z "$buildnum" ]; then
        echo "No build number in $plist"
        exit 2
    fi
    buildnum=$(expr $buildnum + 1)
    /usr/libexec/Plistbuddy -c "Set CFBundleVersion $buildnum" "$plist"
    echo "Incremented build number to $buildnum"
else
    echo "Not incrementing build number as source files have not changed"
fi

3. Be sure to set the permissions (e.g., chmod 777 *)

4. In your Xcode target, go to ‘Build Phases’ and add a new ‘run script’ phase (see image).

5. In the input field (where it says “Type a script or drag a script file from your workspace to insert its path”) enter this:

${PROJECT_DIR}/tools/bump_build_number.sh "${PROJECT_DIR}/${INFOPLIST_FILE}"

6. Change a file (so that the change flag is tripped in the script) and build. Verify the build number is updated.

You can view the build output in the Report Navigator (View>Navigators>Show Report Navigator).