Step-by-Step Guide To Add Upload testflight Using Fastlane

CodeTrade India
4 min readFeb 28, 2024

--

Are you a Flutter developer or iOS developer, and you’re tired of uploading ipa files on testflight with the manual approach and looking for some automation approach by which you can save your time and make yourself more productive? Don’t worry, you’re at the right place. Here we will guide you to achieve the same. We are gonna use Fastlane for the CI/CD pipeline.

CI/CD Pipeline for iOS | CodeTrade.io

CI/CD Pipeline for iOS

Continuous integration and continuous delivery (CI/CD) is a set of practices that automates the software development and delivery process. CI/CD pipelines can help teams to build, test, and deploy their software more quickly and reliably.

A CI/CD pipeline for iOS is a set of automated steps that build, test, and deploy your iOS app. It is a way to streamline your development process and ensure that your app is of high quality and ready for release.

Let’s deep dive into the CI/CD Pipeline for iOS with flavor using Fastlane. With the example of the CI/CD pipeline for iOS, you can better understand the flavor using Fastlane. We use the ‘com.example.flutter.app’ package name (bundle identifier), in this package name we have three flavors.

  • dev
  • prod
  • stage

Prerequisite

Before you proceed with the CI/CD pipeline integration with Fastlane, it is essential to have -

  • Initial setup for Fastlane using the Fastlane Flutter Complete Guide
  • An Active AppStore Developer Account with a subscription
  • App-specific password from Apple developer console
  • Apps should be created on Apple Console with the above flavors
  • Text Editor(we’ll use VS Code for this example).
Build CI/CD Pipeline for iOS with Flavour using Fastlane | CodeTrade.io

Steps to Add Upload testflight Using Fastlane

To add upload TestFlight using Fastlane, you will need to follow the given process:

1. Change Fastlane AppFile

Make changes in Fastlane AppFile according to your requirements. In our example, we make changes in the Fastlane Appfile as shown below code,

# The bundle identifier of your app
app_identifier("com.example.flutter.app")

# Your Apple Developer Portal username
apple_id("abc@codetrade.io")

# App Store Connect Team ID
itc_team_id("123456789")

# Developer Portal Team ID
team_id("ASDFGHJLML")

2. Use Environment Variable

In our case, we use the following environment variables you can use the same if you want.

  • FASTLANE_USER: Your developer user account
  • FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: Your Apple app-specific password
  • WORKSPACE: The path to your workspace file
  • EXPORT_METHOD: The export method to use when creating the IPA file
  • ARCHIVE_PATH: The path to the archive file generated by Fastlane
  • OUTPUT_DIRECTORY: The path to the directory where the IPA file will be saved
  • DEV_APP_ID: The app identifier for the development flavor of your app
  • STAGE_APP_ID: The app identifier for the staging flavor of your app
  • IPA_PATH: The path to the IPA file generated by Fastlane

You can use these same environment variables in your own Fastlane Fastfile. To do this, simply add them to the ENV dictionary in your Fastfile. For example:

FASTLANE_USER=abhishek.karad@codetrade.io 
FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD=” Enter Your Password”
WORKSPACE=Runner. xcworkspace
EXPORT_METHOD=app-store
ARCHIVE_PATH=./build/Runner.xcarchive
OUTPUT_DIRECTORY=./build/Runner
DEV_APP_ID="com.example.flutter.app.dev"
STAGE_APP_ID="com. example. flutter.app.stage"
IPA_PATH=". /Runner. ipa"

3. Create Lane

Once you have added the environment variables to your Fastfile, you can use them in your lanes. Here, we will create only one public lane and the other will be private. you can make all three public if you want.

  • flutter_app -> public lane
  • flutter_app_dev -> private lane for dev flavor
  • flutter_app_prod -> private lane for prod flavor
  • flutter_app_stage -> private lane for stage flavor

For example,

default_platform(rios)
platform :ios do
desc "Flutter App"

lane :flutter_app do
flavor = UI. input ("Which Flavor do you want to upload? ")
puts ("Generating '#{flavor}' Build...")
case flavor
when "dev"
flutter_app_dev
when "stage"
flutter_app_stage
when "prod"
flutter_app_prod
else
UI. user _error! "Please choose the proper option: #{flavor. inspect]"
end
end

4. Provide Definitions for Lanes

Here we’re providing definitions for the above lanes, for prod and stage lanes you can simply replicate this step by changing the app identifier. In our case, we provide definitions for the above lanes, for prod and stage lanes you can simply replicate this step by changing the app identifier.

Note: for production use `upload_to_testflight` only

# Build lane for Flutter App Dev 
private_lane :flutter_app_dev do
puts ("Copying GoogleService-Info.plist.....");

# copy respective GoogleService-Info.plist according to flavour
sh "cp -r . ./Runner/Firebase/dev/GoogleService-Info.plist ../Runner/GoogleService-Info.plist"
puts ("Incrementing build number....");
# The initial version of the app, in case you want to create a new version change the version here
version = "1.0.0"

# This method will fetch the last build number for the version from the developer console
latest_release = latest_testflight_build_number(
version: version,
app_identifier: ENV['DEV_APP_ID']
)
# incrementing the build number puts ("Building Dev 10S App.....");
increment_build_number({ build_number: latest_release + 1 })
# This is a private lane that we're using to build our ios app with the specified scheme puts ("Dev 10S App Built.");
build_flutter_ios_app (scheme: "dev")
puts ("Uploading Dev iOS App to testflight.....");
# Here we upload the build of the testflight
upload_to_testflight(
#set it to false if you want to close the lane after the uploaded build is available on testflight
skip_waiting_for_build_processing: true,
app_identifier: ENV['DEV_APP_ID']
)
# If the lane is prod skip the above lane and use the below one
# upload_to_testflight
puts ("Dev 10S App uploaded to testflight.....");
end

5. Build an iOS App According To the Scheme

Build an iOS app according to the scheme. In our example, We use the private lane to build the iOS app according to the scheme.

Continue Read: https://www.codetrade.io/blog/build-ci-cd-pipeline-for-ios-with-flavour-using-fastlane/

--

--

CodeTrade India

Top-notch custom software development service provider | Open edX Development | Odoo Development Agency | AI & ML Development | Mobile App Development