Published in


GitLab-CI & Fastlane

GitLab CI is very user-friendly, as an individual developer you don’t need to build a Jenkins server anymore, GitLab CI is all set for you. Let’s take a glance at the project I am going to introduce and how about the GitLab CI help us.

Today’s demo project is BowlingGame which contain Unit testing and UI testing, the CI part we use xcodebuild for testing, xcsummary for XCtest report generating and use fastlane for testflight uploading, so you need to install xcodebuild, and fastlane before start.

Part 1 setting fastlane and .yml:

  1. init fastlane: follow the instruction fastlane will guild you complete the information including app_identifier, apple_id, itc_team_id, team_id… etc, or you can check it in path /yourProject/fastlane/Appfile.
// 1. init fastlane$ cd ~/.../yourProject$ fastlane init$ choose 2 // Automate beta distribution to TestFlight$ import your AppleID for testFlight uploading$ Select App Store Connect teams$ Select develop teams

2. Set fastlane/Appfile: This file indicate the apple_id and team_id, etc..

app_identifier("") # The bundle identifier of your app
apple_id("") # Your Apple email address
itc_team_id("123456") # App Store Connect Team ID
team_id("12AB34CD56") # Developer Portal Team ID

3. Set fastlane/Appfile: This file is the main setting of fastlane.

default_platform(:ios)platform :ios do// Select the Xcode path for compile,
// If you have different Xcode version you should set this parameter before_all do
xcode_select "/Applications/"

// Auto add build
desc "add build number"
lane :addBuild do
// upload_to_testflight, set scheme you are going to archive
// set bundle id and its relate rovision profile
desc "Push a new beta build to TestFlight"
lane :betaUAT do
scheme: "targetScheme",
export_method: "app-store",
export_options: {
provisioningProfiles: {
"" => "UAT Provision Profile"

4. Set .yml file: This file tells GitLab CI what to do, which steps should be done

stages:- UIAndUnitTestingiPad- AddBuild_CommitAndPush_Archive_for_archiveUAT- Archive_for_releasevariables:LC_ALL: "en_US.UTF-8"LANG: "en_US.UTF-8"Test_iPad: // This name will show on gitlab-ci consostage : UIAndUnitTestingiPad //stageexcept: // execute except following branchs- archiveUAT- archiveBST- archiveProdscript :- sleep 3- xcodebuild -workspace youProject.xcworkspace -allowProvisioningUpdates -scheme test_scheme -destination 'platform=iOS,name=KiPad' testallow_failure: falseAddBuild_CommitAndPush_Archive_for_archiveUAT:stage: AddBuild_CommitAndPush_Archive_for_archiveUATonly:- archiveUATscript:- pod install- fastlane ios addBuild- git add .// Use -m "[skip ci]" to prevent re-hook pipeline
- git commit -m "Auto Increased build number" -m "[skip ci]"
- GIT_SSL_NO_VERIFY=true git push HEAD:archiveUAT- fastlane ios betaUATArchive_for_release:stage: Archive_for_releaseonly:- releasescript:- pod install- fastlane ios addBuild- git add .- git commit -m "Auto Increased build number" -m "[skip ci]"- GIT_SSL_NO_VERIFY=true git push HEAD:archiveUAT- fastlane ios betaUAT

5. Release Strategy:

- master1. run test (Prod)2. archive (Prod)---- release:1. run test (UAT, Prod)2.add build number3.commit and push4.archive (UAT)---- develop:
1. run test (UAT, Prod)
---- others:
1. run test (UAT, Prod)

Error Handle and Tips:

Q: Missing password for user running in non-interactive shell
A: Cause the missing of keychain
S: Just clone a project without fastlane folder, and run
$faselane init on the runner manually, than selected upload to testflight, finished the settings above, and run$fastlane ios betaUATBefore fastlane upload the archive to testFlight, it will ask you for app-specific password which you can set in, it will save in keychain once you import your app-specific password, than fastlane can upload to testFlight cause this password had store in keychain (Apple Persistent State Encryption) as follow.
Q: Job's log exceeded limit of 4194304 bytes.
A: log to bid, just set more for it
S: set output_limit in config.toml locate in runner's /Users/yourAccount/.gitlab-runner/config.toml
name = "ios"
output_limit = 8192 // Set this
url = ""
token = "the registertoken"
executor = "shell"

Part 2 set GitLab runner:

  1. move to GitLab open your project, see the left slider menu, select CI/CD
move to GitLab open your project, see the left slider menu, select CI/CD

2. scroll to Runner section and disable Shared Runners for this project, we will use Specific Runner for CI/CD

3. open your terminal

Just make sure you have already install gitlab-runner, if not got install it. We need to register the git runner for our mac

gitlab-runner registergitlab-runner installgitlab-runner startgitlab-runner run

Now all set, you may push some commit to test everything

Recommended from Medium

Lawyers in Utah

lawyers in utah

Comparator comparing in Java 8

Just another Git Cheat Sheet

Re-Inventing Workflow Automation For The World Of Data

Here’s a new proposal to encapsulate Domain Layer.

Certified Kubernetes Administrator (CKA) 2020 Exam Changes

Emergent Design with Clean Code

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


I am Red, an iOS developer, I have hands on experience in iOS, Flutter, familiar with RxSwift Moya Unit/UI testing and Gitlab-CI.

More from Medium

Clean Architecture in iOS

Adapter pattern in practice by swift

[RxSwift] Delegate Proxy

Use async URLSession with server-side Swift