Upload your application to TestFlight using Fastlane

Kanan Abilzada
4 min readNov 3, 2021

--

In this tutorial, we will learn how to create certificates and upload our app to TestFlight using Fastlane. Fastlane is an open-source tool that automates your works. Before starting this process make sure that you created your app in App Store Connect and added an app identifier inside here (you also can create it with Fastlane). Let’s get started.

Setup Project

First thing I’m creating a brand new project for us.

Okay, our project is ready now go to Fastlane's documentation page. You can see iOS, Android, and Cross-Platform on there. We’ll focus on the iOS setup.

Setup

1.

Go to the iOS Setup page and as you see there are some options to install it. I’ll use “Bundler”. Open a terminal and run this command

sudo gem install bundler

Okay, Bundler added to our computer.

2.

The second thing is we must create “Gemfile” in our root directory add this line of code inside it.

source "https://rubygems.org"gem "fastlane"

3.

Run this to update

bundle update

Okay, our bundler setup is ready. In now we can init fastlane.

4.

Run the below code in your project directory.

fastlane init 

After running this command you can see “What would you like to use Fastlane for?”. I’ll choose “4” for now. I want to do this process manually.

(it would ask to continue, press Enter) And our Fastlane folder is ready, if you open it you can see 2 files: AppFile and Fastfile. We’ll use Fastfile. Double click on Fastfile and you’ll see this:

Let’s focus on the below code:

default_platform(:ios)platform :ios do
desc "Description of what the lane does"
lane :custom_lane do
# add actions here: https://docs.fastlane.tools/actions
end
end

Delete all code inside do as this, just keep these lines. We’ll add codes to here in later.

platform :ios do

end

Creating Certificates

You need to create a “match file” to create certificates. Please run this in the terminal in your project directory.

sudo fastlane match init

1. git
2. google_cloud
3. s3

  1. We will choose “git” to keep our certificates. Please type 1.
  2. After URL of the Git Repo: paste repo URL which is your certificates will keep.

After that, if you look at to Fastlane directory you can see Matchfile created.

Open Matchfile and update app…………………..

Then, run the below commands in order:

sudo fastlane match development
sudo fastlane match appstore

Well done! If you look at to GitHub repo you can see certificates created successfully :)

Okay, next step we will upload our project to Testflight…

Uploading To TestFlight

1. Build app

The second command will be for TestFlight upload. First we’ll build our app and later upload to TestFlight.

Let’s write “_build_app” command:

desc "Builds Release-Production & uploads to App Store Connect"
lane :_build_app do
match(
app_identifier: MY_APP_ID,
type: "appstore",
readonly: true
)
settings_to_override = {
:BUNDLE_IDENTIFIER => "MY_APP_ID",
:PROVISIONING_PROFILE_SPECIFIER => "MY_PROVISION PROFILE",
:DEVELOPMENT_TEAM => "MY_TEAM_ID"
}
increment_build_number
gym(
workspace: "YOUR_WORKSPACE_NAME",
scheme: "XXX",
configuration: "Production",
xcargs: settings_to_override,
export_method: "app-store",
export_options: {
provisioningProfiles: {
MY_APP_ID => "MY_PROVISION PROFILE"
},
output_name: "ReleaseApp.ipa"
)
end

You can run your new command in now. End of this you’ll see ipa and dSYM created. In now we can upload our app to TestFlight.

2. Upload app

Add this line of codes for upload

desc "Uploading app to TestFlight..."
lane :_upload do
_upload_to_testflight(
username: "MY_Apple_ID",
app_identifier: "APP_IDENTIFIER",
)
end

Well done! Let’s run our next command

Run “_release” in terminal. You’ll see that you must implement “FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD” for upload app. So, to do that go to your apple account and go to the “Security” section. Click Generate Password for the app.

After creating a new password come back to AppFile which is that it was created at the same time with Fastfile and add this in here

ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "YOUR-GENERATED-PASSWORD"

Okay, in now run command again please. At the end of uploading process you’ll see that our application successfully uploaded to TestFlight :)

Hope, this made your work easier. See you later :) Don’t forget smile ;)

Resources:

--

--