Setting up TeamCity for iOS build uploads to Fabric Beta(Crashlytics)

Jason Schloer
2 min readNov 11, 2015

--

This is a follow up to my previous post on how to setup TeamCity with Fabric beta for Android. The idea with iOS is the same, but the build configuration is a bit more complicated.

The first thing we do is grab the pull request number from TeamCity and append that to our version(you could use build number if you prefer). Start by creating a new build step in your build configuration. I called mine “Update version number”. We will use a command line runner with a custom script run type. For the script we use the following:

export PULLREQUEST=`echo %teamcity.build.vcs.branch.IOS_IOSPullRequests% | sed “s/refs\/pull\/\(.*\)\/head/\1/” | sed “s/refs\/heads\/develop/develop/”`
echo Found pull request number $PULLREQUEST
export VERSIONNUM=$(/usr/libexec/PlistBuddy -c “Print CFBundleShortVersionString” “%teamcity.build.workingDir%/Info.plist”)
export NEWSUBVERSION=`echo $VERSIONNUM | awk -F “.” ‘{print $3}’`
export NEWVERSIONSTRING=`echo $VERSIONNUM | awk -F “.” ‘{print $1 “.” $2 “.’$NEWSUBVERSION’-’$PULLREQUEST’” }’`
echo updating the Version number to $NEWVERSIONSTRING
/usr/libexec/PlistBuddy -c “Set :CFBundleShortVersionString $NEWVERSIONSTRING” “%teamcity.build.workingDir%/Info.plist”

This just grabs the pull request id from a TeamCity variable and appends that to the version name. I got most of that script from here.

Next up I like to remove any existing archive, so I setup another command line build step to run:

rm -Rf archive/<appName>.xcarchive

Substitute <appName> with the name of your application.

Now I set up a build step to build our archive. I use the built in Xcode project runner with the advanced options set for archive builds and the archivePath variable.

Again, change <appName> to your app name.

In order to upload to Fabric beta, we need an ipa. I create mine with another command line runner. I first delete any existing ipa and then generate a new one from the archive created in the previous step.

rm archive/<appName>.ipa
xcodebuild -exportArchive -exportFormat ipa -archivePath archive/<appName>.xcarchive -exportPath archive/<appName>.ipa

The last step is uploading to Fabric beta. We do this according to the Fabric beta documentation.

./Crashlytics.framework/submit <APIKEY> <BUILD_SECRET> -ipaPath archive/<appName>.ipa \
-notesPath release.txt \
-emails email@server.com

At this point you should be able to run the build and have it show up in Fabric beta. We have ours setup to auto build any pull request. Check out the Android instructions for help with that. Also, take a look at the other post I wrote on creating release notes for you build based on the commits in your pull requests.

--

--