DEV Community

CodeTrade India Pvt. Ltd.
CodeTrade India Pvt. Ltd.

Posted on

Steps to Add and Upload testflight Using Fastlane

Let’s deep dive into the CI/CD Pipeline for iOS with flavour using Fastlane. With the example of the CI/CD pipeline for iOS, you can better understand the flavour using Fastlane.

Build CI/CD Pipeline for iOS with Flavour using Fastlane

We use the ‘com.example.flutter.app’ package name (bundle identifier), in this package name we have three flavours.

  1. dev
  2. prod
  3. 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
  1. com.example.flutter.app.dev for Dev flavour
  2. com.example.flutter.app.dev for Production flavour
  3. com.example.flutter.app.dev for Stage/Testing flavour
  • Text Editor(we’ll use VS Code for this example).

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("abhishek.karad@codetrade.io") 

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

# Developer Portal Team ID
team_id("ASDFGHJKKL")


Enter fullscreen mode Exit fullscreen mode

Change Fastlane AppFile

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" 


Enter fullscreen mode Exit fullscreen mode

Use Environment Variable

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 flavour
  • flutter_app_prod -> private lane for prod flavour
  • flutter_app_stage -> private lane for stage flavour

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
Enter fullscreen mode Exit fullscreen mode
Enter fullscreen mode Exit fullscreen mode



  1. 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.

Click the given link to view the complete steps to Add and upload testflight Using Fastlane in Flutter.

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

Keep Learning....!

Top comments (0)