TestFlight Easy Automation
By: Mike Chartier
Tags: iOS, Xcodebuild, Xcode, Automation

Are you using Xcode to archive and upload builds to TestFlight? Are you tired of waiting for builds to finish and stepping through the numerous manual steps to get your build uploaded to TestFlight? There must be an easier way right?

When you get to this point you begin searching for automation tools. You have many options out there and they can be quite powerful and flexible. However, if you just want something simple to get started then you will probably find these tools overly complicated. After all, the whole point is to save time!

So let’s get to it. Here is a very simple way to get started with automation using Apple’s native developer tools. In a few minutes you will see how easy it is to use the CLI to deploy your app to TestFlight and the app store.

Step 1

The First step is to create a new plist file. The purpose of this plist file is to capture all of the information that you normally provide to Xcode when you distribute your app. For example, Xcode asks if you want to upload or export, if you want to stripe Swift symbols, do you want to include bitcode, etc. All of these settings can be customized in a plist file so you do not need to step through all of these questions manually.

This first example is ideal for developers who want to upload their build to TestFlight using the default settings. Read part 2 of this article to see how you can customize many of these settings.

export.plist example file:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>method</key>

<string>app-store</string>

<key>destination</key>

<string>upload</string>

</dict>

</plist>

Use your favorite text editor and create a file called export.plist and copy the text from the example above. Save this file in your project home directory.

Step 2

For the next step you will need to determine the name of your Xcode scheme and the name of your Xcode project (or workspace). If you already have those just skip ahead to the next part.

Normally when you create a new Xcode project, Xcode will automatically create a default build scheme for your project, and it will give this scheme the same name as your project. Your build scheme defines how to build your project as well as how to archive your build for distribution to TestFlight or some other. You can find the name of your build scheme in Xcode along the top row just next to the run/stop buttons.

Now you need the name of your Xcode Project or Workspace. Not all projects will have a Workspace. If you don’t know which one you have then just look at the files in the root directory of your project. If you have a file with the extension “.xcworkspace” then you have a workspace.

MyProject.xcodeproj

MyProject.xcworkspace

Step 3

We are ready to build! Open a terminal and navigate to the root directory of your project. Once there you will enter the CLI commands below. Just replace “SimpleApp” with your project names.

$ cd ~/Xcode/SimpleApp

$ xcodebuild archive -workspace SimpleApp.xcworkspace/ -scheme Scheme1 -archivePath ~/Downloads/SimpleApp.xcarchive

$ xcodebuild -exportArchive -archivePath ~/Downloads/SimpleApp.xcarchive -exportPath ~/Downloads/ -exportOptionsPlist export.pilst

If you are NOT using a workspace then your CLI commands will be a little different:

cd ~/Xcode/SimpleApp

$ xcodebuild archive -project SimpleApp.xcodeproj -scheme Scheme1 -archivePath ~/Downloads/SimpleApp.xcarchive

$ xcodebuild -exportArchive -archivePath ~/Downloads/SimpleApp.xcarchive -exportPath ~/Downloads/ -exportOptionsPlist export.pilst

If all goes well your archive will be created and uploaded to TestFlight without any intervention from you!

To fully automate the process just save those two commands in a new text file in your project home directory. Now you can just run that file anytime you need to distribute a build. Remember to use chmod to make the file executable.

# first create the file called 'build'

chmod 777 build

./build

Notes and Reminders

Always make sure to increment your build number before creating a new build archive. If you don’t you will get an error when you upload the new archive to appstoreconnect.

If you need to customize settings for your project please see part 2 of this article.