Bitbucket + Bitrise: Configuring Continuous Integration for an iOS app

This is a guest post written by Ivan Parfenchuk. Ivan is an independent iOS and Ruby developer passionate about building delightful experiences. Connect with him on Twitter @gazebushka.

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 & 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 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 release branch or merges Pull Request to 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 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.