Setup CI/CD using Fastlane & Gitlab runner >> Part-1 Fastlane setup and runner register

kumaresh
4 min readNov 15, 2022

--

If you are an iOS developer, you know the pain of releasing the build to the QA team and Appstore deployment.

Now we have plenty of different ways to achieve this process like

  • Code Magic
  • GitHub action
  • GitLab pipeline
  • Fastlane and more on

In this part, we are going to achieve this CI/CD setup with help of the Fastlane tool and GitLab runner.

Prerequisites

First, we will see what the necessary thing needed for this process

  • Xcode (with the respective project)
  • Gitlab account (make sure your project is pushed in the respective repo)
  • Ruby (make your machine have ruby)

At the end of this part, you learn below items

  • Gitlab runner register on your machine
  • Fastlane setup on your machine

Gitlab runner register

I'm using homebrew to install the GitLab runner instant.

If your machine doesn't have a homebrew. please visit https://brew.sh/ and install.

Open your terminal and follow the

  1. Install Gitlab runner as a service
brew install gitlab-runner

2. Start Gitlab runner

brew services start gitlab-runner

Gitlab runner is installed

3. Register GitLab runner

gitlab-runner register

Click enter to run the command. then comment line will ask your some inputs

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/): 
https://gitlab.com/

After, then need to put the GitLab-ci token from GitLab

Please enter the gitlab-ci token for this runner: <<Your ci token>>

you can get the GitLab-ci token from GitLab dashboard

go to gitlab.com → login →click project → settings → CI/CD → expend Runners menu

you will see like below

Gitlab runner section

After that, you will prompt the following qustions

Next in the register process suggests the name of your Mac as a description 
for the runner. You can enter something different if you like, or
just hit return to continue.

Please enter the gitlab-ci description for this runner: <<Your Description>>

Click enter, then it will ask for the tag name

Please enter the gitlab-ci tags for this runner (comma separated): <<Tag name>>

Enter your own tag name and click enter.

Note down this tag name we are going to use this tag name later.

Gitlab runner registered and give a unique ID

after that need to select the executor script

Please enter the executor: docker-ssh, shell, ssh, virtualbox, docker+machine, 
kubernetes, docker, parallels, docker-ssh+machine, custom: Shell

Enter Shell and click enter

4. Verify the GitLab runner

gitlab-runner verify

Finally, the GitLab runner register successfully. You will see this registered runner in the runner section.

Then we move to the Fastlane installation

Fastlane Installation:

For installing the Fastlane we have multiples ways. now I'm using the home brew.

  1. Open Terminal and enter the below command
brew install fastlane

2. Then navigate to the project director. using CD command

3. Init Fastlane

fastlane init

On the succession of this command, the Fastlane folder will be created on the project root directory.

Inside the Fastlane folder. you will see the below files.

  • Fastfile
  • Appfile

Make sure these files are generated.

After that need to set the environmental variables in the bash profile.

4. Setup Env variables for Fastlane

  • Open finder → Go, then enter the below path
~/.bash_profile

If you don’t have a bash profile. Then create it and follow the steps given

Create bash profile: https://redfinsolutions.com/blog/creating-bashprofile-your-mac

5. Enter the below lines in .bashprofile

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Gem File Creation

It is recommended that you use a Gemfile to define your dependency on Fastlane. This will clearly define the used Fastlane version, and its dependencies, and will also speed up using Fastlane.

To create a Gem file follow the below step

  1. Open a terminal and navigate to the project root folder and enter below command
./Gemfile

2. Open the project root folder and make sure Gemfile is created.

3. Open Gemfile and enter the below lines

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

Sit and relax we have completed 10% of CI/CD in the Part 1 section. We will see the rest of the fastlane stages and gitlab yml file coding in upcoming sections.

Stay tuned 🤖🤖

Happy Coding…😎👨🏻‍💻

Part 2: Fastlane stages Build Stage, Unit test , Code Coverage , Firebase App distribution, Appstore Deployment, Slack Notification

--

--