Auto-Increment Build Number

Apple Docs

I don't know if this Doc existed back when I wrote this post & created the script. 

Xcode appears to be auto incrementing the Build Number now (2023) in Cloud builds.  And Apple has an article on the topic.

Xcode Cloud seems to auto increment the build number now (out of the box) but that build number does not come back into the local project's config.  My project's build number is still sitting at 1.  I guess getting these in sync is a problem left for the developer.

Xcode Build Phases

In the Navigator select the project file, then the App Target; select the Build Phases and you will add a new phase something like: "Increment BUILD NUMBER" ( to add a phase click the plus symbol + top left of the pane and select "New Run Script Phase").

Copy and drop this shell script into the box.

git=`sh /etc/profile; which git`

bundleVersion=`"$git" rev-list --all |wc -l`

/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $bundleVersion" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"


The script gets the revision number from git sets that as the bundleVersion variable and then uses PlistBudy to add the string into the proper info plist.