Over a million developers have joined DZone.

iOS Project (CI/CD): Integrating GitLab-CI, Fastlane, HockeyApp, and AppCenter

DZone 's Guide to

iOS Project (CI/CD): Integrating GitLab-CI, Fastlane, HockeyApp, and AppCenter

Follow the key steps to create a base framework for CI/CD process.

· Integration Zone ·
Free Resource

There are many ways to implement CI/CD for iOS projects, and choosing the right combination of technology all depends on your project type, existing infrastructure, and customer requirements. Here, we’re using Fastlane — an open-source technology for HockeyApp/AppCenter uploading, but Fastlane itself is mature and capable of handling all tedious tasks. Here is the easiest way to setup CI/CD by using GitLab-CI, Runner, Fastlane, and AppCenter/HockeyApp for final app distribution.

Image title

Please follow the below key steps to create a base framework for CI/CD process:

  • Access to existing GitLab account/Create a new one

  • Setup GitLab-Runner in MacOSX build machine

  • Register GitLab-Runner with GitLab-CI

  • Install Fastlane in build/development machine

  • Enable GitLab-CI and Fastlane

  • Access to existing AppCenter/HockeyApp account or create a new one

Before starting CI/CD implementation, make sure that GitLab account is ready and the code has been pushed to the repository from your development machine.

Setting up GitLab-Runner (MacOSX Machine)

$ sudo curl --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-darwin-amd64
$ gitlab-runner install

Register GitLab-Runner Instance With Your GitLab Account

$ sudo gitlab-runner register

Before executing the above command, please write down or copy gitlab-ci token and gitlab-ci coordinator url from GitLab account -> Settings -> CICD

Image title

Image title

Once you are done with the gitlab-runner registration process, start the GitLab-Runner by executing the following command:

$gitlab-runner start

Please make sure the runner status in GitLab account and note that "tag name" can be used to identify the specific GitLab-Runner instance, which can be added in the .gitlab-ci.yml file.

Image title

Installing Fastlane in Build/Development Machine

You need to install Fastlane on both the build and development machine in order to test and configure.

Execute the following command from your build and development machine "Terminal" to install Fastlane.

$sudo gem install fastlane -NV

After installing Fastlane in your development machine, go to project root directory and initialize Fastlane dependencies for Swift. The Swift version of Fastlane is in Beta stage, and this will not support Fastlane-Plugins. If you choose AppCenter or any other distribution platform that requires additional Fastlane-plugins, then you can avoid the "swift" parameter from the below command.

$fastlane init swift

Once initialization is completed, open "Fastfile.swift" or "Fastfile" and insert the following code for uploading iOS binary to HockeyApp or AppCenter.

func appBetaDistributionToHockeyApp() {
//Fastlane API to upload signed ipa to HockeyApp
hockey(apiToken:<<Token from HockeyApp account>>, ipa: <</ios-builds/beta/hellogitlab.ipa>>, notes:<<any notes here>)
func appBetaDistributionToAppCenter() {
//Fastlane API to upload signed ipa to AppCenter
    api_token: "<appcenter token>",
    owner_name: "<your appcenter account name>",
    app_name: "<your app name>",
    ipa: "<path to iOS build>"

Install Fastlane — AppCenter Plugin

To upload application binary to AppCenter, you need to install the AppCenter-plugin for Fastlane.

fastlane add_plugin appcenter


Enable GitLab-CI

To enable GitLab-CI, create a new file called ".gitlab-ci.yml" and save it in your project root directory. Insert the following xcodebuild commands to the yml file to clean, buildarchive, and export ipa from GitLab-Runner. It is mandatory to create an export options plist file with proper code signing identity and details.




- "xcodebuild -workspace HelloGitLab.xcworkspace -scheme HelloGitLab clean"

- xcodebuild -workspace HelloGitLab.xcworkspace -scheme HelloGitLab -configuration Debug CODE_SIGNING_REQUIRED=“NO” CODE_SIGNING_ALLOWED=“NO” -destination generic/platform=iOS archive -archivePath /ios-builds/archive/path/HelloGitLab.xcarchive

- "xcodebuild -exportArchive -archivePath /ios-builds/archive/path/HelloGitLab.xcarchive -exportPath /ios-builds/dev/ipa/path -exportOptionsPlist /ios-builds/dev/exportoptions-development.plist”

- "fastlane appBetaDistributionToHockeyApp"

stage: build


- ios



Please validate your .gitlab-ci.yml file by using built-in GitLab validation tool or any yml lint tool available online.

Export Options plist

It is recommended to create multiple "export options" plist files for different targets like development, ad-hoc, enterprise, etc. with different code signing and provisioning profile details. Below is the sample one for development target.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<key>bundle identifier</key>
<string>Provisioning profile name</string>
<string>Signing certificate name</string>

Once you complete all these steps, do a fresh commit and push the code into the GitLab repository and see the GitLab pipeline result.

Happy coding!

ios ,xcode ,gitlab ,cicd ,swift ,gitlab runner ,integration ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}