Using Gitlab CI/CD + Fastlane for iOS Project — Part 3

Phan Quang Hoàng
4 min readApr 19, 2019

--

We installed swiftlint and code coverage in part 2. Now we will go ahead with Fastlane match. To avoid wasting time when work in a team, manage signing and provision is very necessary.

You can imagine the following workflow to share the signing and provision in the team:

  1. Export certificate in Keychain into .p12 file
  2. Download provision in Apple Developer
  3. Give out this files for each member in the team.

If a certificate or provision is deleted, expired, a new member join with team or a new device added, you must start all above steps again.

Let’s make it more automated right now.

First, we need to have a private repository to store certificates and provisioning. Login to Gitlab to create one.

Next, we will initial match file in the project:

$ fastlane match init

You will copy and paste your certificate repository when terminal require. Do you finish? Now let check in your Fastlane directory, you will see Matchfile in there.

Before continue with match, you must login to apple developer to create new bundle for your project. I ignore this step. You will do by yourself.

Are you done? Okay, go ahead.

In terminal, you type the following command and input when terminal require your input:

$ fastlane match development

When you fill password to encrypt certificate repo, you should fill a password to remember easy and do not contain special characters.

Now, let check certificate repository again, you will see certificates and profiles uploaded.

Final step with Fastlane to deploy app to hockey app for testing.

  • Create API token:
  • Paste this script at top of Fastfile:
ENV["MATCH_GIT_URL"] = "<YOUR_CERTIFICATE_REPO>"ENV["FASTLANE_OUTPUT_DIRECTORY"] = "fastlane/output"@output_directory = ENV["FASTLANE_OUTPUT_DIRECTORY"]# git url of match@match_git_url = ENV["MATCH_GIT_URL"]
  • Create deploy action
desc "Upload build to hockey"lane :deploy domatch(git_url: @match_git_url,type: "development",app_identifier: "<your_bundle_id>",readonly: true)# increase build number everytime when packaging a new buildincrement_build_numberbuild_app(scheme: "CoinMarket",workspace: "CoinMarket.xcworkspace",clean: true,output_directory: @output_directory,configuration: "Debug",silent: true,export_method: "development",export_options: {signingStyle: "manual", # or manual , automaticcompileBitcode: true,uploadBitcode: true,provisioningProfiles: {"< your_bundle_id >" => "<name_of_provisioning_has_been_createed_by_match>"}},sdk: "iphoneos")hockey(api_token: "<your_hockey_api_token>",ipa: "#{@output_directory}/CoinMarket.ipa")end

To increase build number every time when packaging a new build we must change version in Build Setting of Xcode:

  • Run deploy action: fastlane deploy
  • Now, check build in hockey dashboard:

We are going to the last step, so fastlane and gitlab CI can talk to each other.

Open .gitlab-ci.yml to configures for them:

$ vim .gitlab-ci.yml

Paste this script in your file:

stages:- lint- unit_tests- deployvariables:LC_ALL: "en_US.UTF-8"LANG: "en_US.UTF-8"before_script:- bundle install --path vendor/bundle- bundle exec pod installlint:dependencies: []stage: lintscript:- fastlane linttags:- iosunit_tests:dependencies: []stage: unit_testsscript:- fastlane testtags:- iosdeploy:dependencies: []stage: deployscript:- fastlane deploytags:- ios

Now we will push our configure to Gitlab:

$ git add .gitlab-ci.yml
$ git commit -m "Add .gitlab-ci.yml file"
$ git push

Then we start Runner to see the result:

gitlab-runner startgitlab-runner run

From now, our development process has been automated, help us save a lot of time. Cheer!

I hope this tutorial can be of great help to you during the iOS software development process, save time for you and your team.

Preferences:

--

--

Phan Quang Hoàng
Phan Quang Hoàng

Responses (3)