Series 2: Using Fastlane to automate In-House and App Store distribution process.

In the previous post we have go through fastlane installation and setup.
We also have done certificates and provisioning profiles synchronisation across the team by using match.

In this post we will fully focus on distribution using Fastlane.
I will walk through step by step how to deploy an in-house QA build and submit a test flight version directly using 1 line of execution using Fastlane.

YES! After you follow this tutorial you only need one line to deploy!
Let’s get started.

Step 1: Check and ensure scheme is setting to use correct configuration.
For both In-house Enterprise QA and App Store TestFlight build will be using Enterprise and App Store configuration respectively.

For In-house Enterprise QA build, we will going use App Center to host all the builds.

You can check Manage Schemes after you have create the new scheme, make sure the scheme is Shared.

Check each of the scheme to ensure that under Archive the configuration is set according to avoid unexpected error happened.

Step 2: Create a manual deployment secret file.

In order to let Fastlane to have the power to execute the deployment process, we need to ensure that able to access some credentials (eg: App Center Token, Apple Developer account etc).
However these information is really important to prevent exposure to the public (although we are using private repo).

Open Terminal (under root folder of the project):

Before we create .manualdeployment.txt, ensure that we add .manualdeployment.txt in .gitignore file so that secret is not committed to the repo.

paste in the information below

Filled in the information respectively:
a. FASTLANE_USER is the apple id used to submit TestFlight build.
b. FASTLANE_PASSWORD is the password of the respective apple id.
c. MATCH_PASSWORD is the passphrase you used to encrypt repo that hosting the certificates and provisioning profiles in Series 1 — Section 5 — Step 2.
d. FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD is the password used to upload TestFlight build to App Store.
e. APP_CENTER_API_TOKEN is the access token use to update In-house QA build to App Center.

Step 3: Create an App Center token.

Login App Center, create a token here.
You can read the detail documentation on how to create the token here.

Copy the API Token and replace app_center_api_token in .manualdeployment.txt.

Step 4: Generate App Store APPLE_APPLICATION_SPECIFIC_PASSWORD.

Since Apple have enabled 2 Factor Authentication (2FA) for all the Apple ID, in order to submit the TestFlight build we need to use app-specific password to by pass the OTP verification.

You can find the comprehensive documentation here on how to create the App-specific password.

Copy the app-specific password and replace apple_application_specific_password in .manualdeployment.txt.

Step 5: Encrypt the .manualdeployment.txt .

The encryption is important to prevent direct exposure of the deployment secret to the public.

Open Terminal (under root folder of the project):

Important: You will be asked to enter a encryption_passphrase to encrypt the file, remember the passphrase you are using!

Commit .manualdeployment.enc and .gitignore to the repo.

Step 6: Create a function to set deployment secret as Fastlane environment variable.

To ensure that Fastlane is able to use the deployment secret, we need create a function to ensure that the environment variable is set before we execute the lane.

Open fastlane/Fastfile

What the function does:
1. Checked if decrypted .manualdeployment.txt exist in the root folder, will reuse the decrypted file to set environment variable so that we no need to enter the encryption passphrase we set in Step 5.
2. Decrypt the secret to file .manualdeployment.txt.
3. Read the .manualdeployment.txt, set the environment variable respectively.

Step 7: Install App Center fastlane plugins.

We will use this fastlane plugins to upload the build to App Center.

Open Terminal (under root folder of the project):

You should able to see Successfully installed plugins at the end.

Step 8: Create a new lane to create In House QA build and submit to App Center.

We should verify that the Fastlane is working perfectly fine before we create a new lane.

By running fastlane lanes you should able to see all the existing lanes.
(You should see nothing if you have no lanes created inside your fastlane/Fastfile.

Add a new lanes into Fastfile.

What the lane does:
1. Retrieve the version number and build number from the project.
2. Fetching provisioning profiles for enterprise from default keychain. (A keychain access confirmation prompt will show when we execute the lane).
3. Archiving the iOS build with enterprise configuration and respective scheme.
4. Upload the build to App Center. (The detail on the params you can find here.)

You are now able to create In House QA build by one line!
Now you can execute fastlane local_inhouse to create and submit an In-House QA build to App Center.

Step 9: Create a new lane to create TestFlight build and submit to App Store.

Since we have different configurations for In-House and TestFlight build, we should create a new lane to deploy Testflight build to ensure that the Fastlane is able handle it properly.

Add a new lanes into Fastfile.

What the lane does:
1. Retrieve the version number and build number from the project.
2. Fetching provisioning profiles for appstore from default keychain. (A keychain access confirmation prompt will show when we execute the lane).
3. Archiving the iOS build with App Store configuration and respective scheme.
4. Upload the build to TestFlight. (The detail on the params you can find here.)

You are now able to create TestFlight build by one line!
Now you can execute fastlane local_appstore to create and submit the TestFlight build to App Store.

jasonchan91 - iOS Engineer who passionate in UX/UI Design. http://jasonchan91.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store