Bitbucket + Bitrise: Configuring Continuous Integration for an iOS app

DZone 's Guide to

Bitbucket + Bitrise: Configuring Continuous Integration for an iOS app

By configuring a CI tool with your app, you open up a world of possibilities for your development and maintenance efforts. Read on to get started!

· Web Dev Zone ·
Free Resource

When iOS applications start growing, at some point it becomes essential to have a quick develop-release-test feedback loop. You can create this loop by doing everything manually, but it can be much quicker and more advanced if you use Continuous Integration (CI) tools.

With a CI tool, you can build up a history of releases and quickly see which build contained what. You can run tests for every build automatically and catch some inevitable bugs. You can have consistency in your release notes. And you can streamline your release cycles, which automates your checklists.

Sound interesting? Let’s try to build this feedback loop using Bitbucket Webhooks, Bitrise, and fastlane.

Deployment Flow

The flow we are going to use for our Continuous Integration is going to look like this:

  1. Create and merge a Pull Request in Bitbucket.
  2. Bitbucket performs a “Webhook” HTTP request to Bitrise.
  3. Bitrise starts building the process and launches fastlane.
  4. fastlane builds the app and sends it to App Store Connect.
  5. App Store Connect processes the build, and it becomes available in TestFlight.

Bitbucket Webhooks and Git Branching Model

Each deployment starts from us creating a Pull Request.

Let’s say your team is using a master git branch for code in the releasable state. It also makes new releases by merging this master branch to the release branch.

The following section describes how to create a Webhook manually. However, if you use Bitrise, it can create a Webhook for you automatically, so, feel free to skip to the Bitrise section.

Manual Webhook Configuration

Next, let’s configure Bitbucket Webhooks so that whenever someone pushes to the release branch or merges a Pull Request to the release branch, the Webhook is triggered.

To do that, go to your Bitbucket repository and click “Settings” in the side menu. Then click “Webhooks” in the “Workflows” section and then click “Add webhook.”

Fill out Title, URL (see below), set Status to Active, and select “Choose from a full list of triggers” for Triggers. The triggers we are going to use are:

  1. Repository: Push
  2. Pull Request: Created, Updated

To get the URL for our Webhook:

  1. Head over to Bitrise, create a new app.
  2. Open the Dashboard -> Your app -> Code tab.
  3. Scroll to the Incoming Webhooks section and click Setup Manually.
  4. Select “Bitbucket Webhooks” and copy the Webhook URL
Continuous integration with Bitbucket

Bitrise and Automatic Webhook Configuration

Bitrise is a platform for Continuous Integration. You can configure different deployment “workflows” in it and have the Bitrise servers build and publish your application. Here are the steps to create a new deployment workflow for our CI setup.

  1. First sign up in Bitrise, go to the Dashboard, and click “Add New App.”
  2. Select “Private” if you want your config and logs to stay private.
  3. Select Bitbucket and connect it to your account.
  4. Click “Auto-add SSH key” or configure SSH access manually.
  5. Enter `release` as the branch name in the “Choose branch” step.
  6. In the Project build configuration, select “fastlane” and check that Fastlane lane is set to `ios release.`
  7. Select the stack that you normally use to build your app or just the latest available Xcode/macOS and click Confirm.
  8. In the last step, “Webhook setup,” click “Register Webhook for me.”

The last step creates a Webhook in Bitbucket, so you don’t have to do anything manually. You can head over to the Bitbucket repository and check the Webhook configuration in Settings -> Webhooks.

In our setup, we are going to use fastlane to build and publish the app to App Store Connect.

Fastlane Configuration

Fastlane is a set of tools for automating development and release processes.

Follow this guide to install fastlane: Setup – fastlane docs.

In short, you need to install Xcode development tools:

xcode-select --install

and then install fastlane via RubyGems

sudo gem install fastlane -NV

or via brew:

brew cask install fastlane

Then open the working directory of your app in the Terminal and initialize fastlane.

cd /path/to/your/app
fastlane init

Select “3. Automate App Store distribution”

Then follow the configuration requests. Fastlane can create and configure the new App Id for you and create a sample deployment “lane.” A lane is just a collection of steps, required to complete some scenario.

Once the configuration is finished, open the Fastfile which has been created and configure the first deployment script. Fastlane has large set of tools for automating various processes like code signing, uploading of screenshots, running tests ,and so on. However, we are going to start with a simple setup:


platform :ios do
  desc "Push a new release build to the App Store"
  lane :release do
    build_app(scheme: "CITest")
    upload_to_app_store(force: true, skip_metadata: true, skip_screenshots: true)

The “release” lane will:

  1. perform a build of your project — build_app(scheme: “CITest”).
  2. Upload the resulting ipa file to App Store Connect — upload_to_app_store. In this guide, we are skipping the fastlane metadata upload.

You can test your setup by opening your project directory in the Terminal and running a fastlane release:

cd /path/to/your/app/directory
fastlane release

Code Signing

If you see problems with code signing, start here: Troubleshooting – fastlane docs. You can use fastlane match to manage code signing, but be careful: if you already have generated Certificates and Provisioning Profiles, match can break things. However, if it’s a completely new setup or you don’t care much about the existing profiles, match is going to speed things up considerably.

We’ll use fastlane match in our example:

cd /path/to/your/app/directory
fastlane match development
fastlane match adhoc
fastlane match appstore

Then open Xcode, turn off Automatic code signing, and select the provisioning profiles that match has generated.

After that, we can add match to our Fastfile:


platform :ios do
  desc "Push a new release build to the App Store"
  lane :release do
      match(type: "appstore", readonly: true)
    build_app(scheme: "CITest")
    upload_to_app_store(force: true, skip_metadata: true, skip_screenshots: true)

Finishing the Bitrise Setup

bitrise setup authentication

Bitrise is building the project on its servers which don’t have any of your passwords and credentials required to code sign and upload your app to App Store Connect. Therefore, we’ll have to share some of those; precisely these two:

  1. Login/password for App Store Connect user.
  2. Password to decrypt your match repository (if you use match).

The App Store Connect user doesn’t have to be the one you use to control your apps. You can create a new user in App Store Connect, which only has access to the app you automate and has at least a Developer role.

Once you set your new App Store Connect user, head over to Bitrise and open Workflow Editor tab and then Secrets. Add two new secrets:

ITUNES_CONNECT_USER and ITUNES_CONNECT_PASSWORD with App Store credentials for this new user. Plus, put the same password into the FASTLANE_PASSWORD secret.

If you use match, add one more secret called MATCH_PASSWORD with the password you used to encrypt the match repository.


That should be it. Try to create a new Pull Request and merge it and see if Bitrise triggers the new build. If everything goes well, you will see the new build in TestFlight and will be able to select it for your new iOS app version.

ios configuration with bitrise

There is much more that you can do with automated deployments, such as:

  1. Testing using a fastlane scan.
  2. Automated build number incrementation.
  3. dSYM uploads to Crashlytics_Raygun_etc.

However, start with simple things first. I hope this guide helps you!

bitbucket, continuous integration, ios, web dev, webhooks

Published at DZone with permission of Ivan Parfenchuk . See the original article here.

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}