iOS Continuous Integration and Delivery using Bitrise and Fastlane — Part 2

Abedalkareem Omreyh
6 min readJun 24, 2019

--

This is a part of a series about iOS continuous integration and delivery.

Part 1: Install Fastlane

Part 3: gym, Pilot and Slack

Part 4: Bitrise!

Part 5: Workflows and Triggers

In our first part, we installed Fastlane and made our first lane “beta”, in this part we will start adding actions to our lane.

Match

The first action we will use is the Match action, Match creates all required certificates & provisioning profiles and stores them in a separate git repository. Every team member with access to the repo can use those credentials for code signing. Match also automatically repairs broken and expired credentials. It’s the easiest way to share signing credentials across teams.

Run the following command line on your project to initialize Match:

fastlane match init

The terminal will ask you where you want to store your certificates, select git

Next, it will ask you the git URL, make a private git repo on Github or Bitbucket and use the URL of that repo.

This will create a Matchfile inside your Fastlane folder. The Matchfile will contain the git repo URL and the type of storage.

Now we will add the match action to our lane and pass the type parameter as appstore as we will build the app for iTunes connect.

match(type: 'appstore')

Next, run the fastlane beta command again, it will ask you about the username enter your username.

Important: You must add the username in your Matchfile, you can find the Matchfile inside the fastlane folder.

Match file

Then it will ask you to enter the app identifier, to not be asked about this value, you can specify it using ‘app_identifier’ parameter in the match action.

match(type: 'appstore', app_identifier: "your_app_identifier")

This is the final look of our beta lane:

Now run the beta lane again, it will ask you about a passphrase for the git repo, this passphrase will be used to encrypt/decrypt your certificates, make sure to remember the password, as you’ll need it when you run Match on a different machine.

Note: If you don’t have an app created on iTunes connect with the same app_identifier then you will get the:
Couldn’t find bundle identifier ‘your_app_identifier’ for the user ‘you_username’ so you need to go to the iTunes connect and create new app.

Now all the required keys, certificates and provisioning profiles are installed for your app. And if you open the git link you will find the files there.

How your certificates repo will look like

Increment the build and version numbers and add badge

Next thing we will do, we will increment the build number and the version number and keep them inside a variable as we will show the version number and the build number on the app icon, the increment version number take a “bump_type” parameter. There are three different values for the bump type: patch, minor and major.

For us, we will increment the patch number, as the beta will be small changes and bug fixes.

version_number = increment_version_number(bump_type: "patch")

And to increment the build number:

build_number = increment_build_number

This is the final look of our beta lane after adding the increment build number and increment version number actions.

Run the Fastlane beta again, you will get an error, this error because Apple Generic Versioning is not enabled in this project, to fix this issue:

1-Open your project.

2-Select your app target.

3-Select build settings.

4-Search for “Apple Generic”.

5-Change the version system to “Apple Generic”.

6- Search for “Current Project Version” and set it to 1

7-Go back to the general tab and make the version number to 1.0.0.

8-Go to info tab and change the “Bundle versions string, short” to 1.0.0, and the “Bundle version” to 1.

Run the “fastlane beta” command again you will get a new error, open your project -> your app target -> build settings, then search for “SRCROOT”, remove “$(SRCROOT)/” and run the beta lane again.

Now everything works fine If you check your project, you will find that the version and build numbers changed.

Now it’s the time to add the badge to the icon, go back to the Fastlane file and add the add badge action.

add_badge(shield: "")

Now “add_badge” action takes deferent parameters, the parameter that we will use is the shield parameter, this parameter adds a shield to your app icon from shields.io, open the website and scroll down to the “Your Badge” section you will find three boxes, the first box is the label, the second is the message and the third is the color, fill the three boxes as in the image below:

Press “Make Badge” you will get the following image:

This what we will get when apply the add badge action to our icon.

Now, in the same way, we will set the shield parameter with

“the_version_number - the_build_number - the_color”

I’ll use the previous build and version number variables and for the color, I’ll use red.

add_badge(shield: "#{version_number}-#{build_number}-red")

Now if you try to run the command you will get an error, because you need to install the “fastlane-plugin-badge” plugin, to install the plugin open the Gemfile in your main directory.

and add this line:

gem 'fastlane-plugin-badge'

Run the command again and you will find that the icons changed!

That's it for this part. If you faced any problem you can add a comment below or send me a message on Twitter or facebook.

Part 3: gym, Pilot and Slack

--

--