07 June 2013

Automagical iOS TestFlight Deployments

A little thing I have done for work is to automatically build the latest code of our iOS projects and push the IPA to TestFlight. After spending a couple of hours trying to get Jenkins to do this, I was getting nowhere and gave up.

I spent about 20 minutes writing a bash script that did everything I needed, launched at 5:30pm via cronjob. The basic gist of it is below.

#!/bin/bash
cd /Shared\ Items/Public/AUTO/project
BUILDDIR="/Shared Items/Public/AUTO/project_build"
NAME="Project"
CONFIGURATION="Ad Hoc"
API_TOKEN="..."
TEAM_TOKEN="..."
# Reset Git
echo resetting
git reset --hard
echo pulling latest
git pull
xcodebuild -workspace $NAME.xcworkspace -scheme $NAME -configuration $CONFIGURATION clean build ONLY_ACTIVE_ARCH=NO CONFIGURATION_BUILD_DIR="$BUILDDIR"
echo $?
echo Generating .ipa file
xcrun -sdk iphoneos PackageApplication -v "$BUILDDIR/$NAME.app" -o "$BUILDDIR/$NAME.ipa"
echo $?
# Zip the dSYM File
echo Generating zip file
/usr/bin/zip -r "$BUILDDIR/$NAME.app.dSYM.zip" "$BUILDDIR/$NAME.app.dSYM"
echo $?
# Upload the build to TestFlight
echo Sending to TestFlight
/usr/bin/curl "http://testflightapp.com/api/builds.json " -F [email protected]"$BUILDDIR/$NAME.ipa" -F [email protected]"$BUILDDIR/$NAME.app.dSYM.zip" -F api_token="$API_TOKEN" -F team_token="$TEAM_TOKEN" -F notes="Build uploaded automatically from Xcode." -#
echo $?
echo Done!
view raw gistfile1.sh hosted with ❤ by GitHub

This is okay for now.. But when I decide to do this for multiple iOS projects I think I will create a little node.js app that will manage projects and be similar to Jenkins. Watch this space.

(This scripts assumes that the build configuration that xcode is building is using the correct distribution that the provisioning profile that your testers on testflight are in)

Will Townsend

Hey 👋 I'm Will Townsend, I hope you enjoyed this post. If you have any questions you can contact me on Twitter, cheers!