Automatic release of iOS apps by using Bitrise and Fastlane
August 24, 2022
Automate and accelerate! In this article, we'll look at Bitrise service and in particular how it can be used in conjunction with Fastlane. We'll explain what it is and carefully guide you through the setup for testing, building and publishing an iOS app.
This article is a follow-up to our previous blog article about Fastlane. If you don't know what it's about, be sure to check it out. Because in the following lines we are already counting on a fully functional Fastlane in an existing project.
What's Bitrise?
Bitrise is a service that opens the door to limitless possibilities in CI (continuous integration) and CD (continuous delivery). Today, it is an essential part of any iterative development. With the CI/CD combination, development teams can more reliably and quickly release new versions of applications for testing as well as for production environments.
Bitrise enables very fast integration of CI/CD into existing projects via a friendly web-based environment. If required, the service can also be run directly on your own server using the available CLI tools. Bitrise also allows applications to be flexibly tested, archived and published regardless of the tools used for development.
We envision using this service primarily for the needs of iOS projects.
Let's get started! Creating a project and setting up an SSH key
As a base, we create a Bitrise project and pair it with the repository where our project is located. We can make the initial setup easier by linking the Bitrise account to one of the popular Git services such as GitLab or GitHub. This way we can select a specific repository without the need for manual configuration.
In order to Bitrise to access the repository, we must first set up an SSH access key. If the linked Git account has administrative access to the repository, Bitrise can take care of setting the SSH key itself. But if it doesn't, you need to create your own SSH key and add it to both our Git service and Bitrise.
Setting a custom SSH key is also unavoidable if your project consists of several repositories (e.g. Git submodules). In this case, we need an SSH key that has access to all the necessary repositories.
Bitrise automatically detects the project type (e.g. iOS or Android) during the creation process and provides us with a basic configuration that includes testing and building the app. We can then customize everything according to our needs.
Code Signing
Since we are in an iOS environment, we need to resolve the issue of app signing before we can further configure the Bitrise project. While there are several methods available to us, the easiest is to use Xcode and the auto-signing option combined with access to App Store Connect using an API key. To do this, we will need the following:
App Store Connect API key with Admin permission
Certificate suitable for exporting the application to TestFlight
Instructions on how to get the App Store Connect key up and running are available directly in the Bitrise documentation. The management of developer certificates will be greatly facilitated by the Fastlane match tool, which can access the necessary certificates directly in our Keychain. We export the correct certificate as a P12file and upload it to Bitrise in the Code Signing section.
If you use manual signing settings in Xcode, you must upload the necessary provisioning profiles to Bitrise along with the certificate.
Workflows
Bitrise allows us to run almost anything we need on the host machine. However, the basic building blocks are the so-called steps, which we choose ourselves according to the needs of the current project. We can find a wide selection of frequently used steps, so it is usually not necessary to write our own script for common situations related to application development.
You can create your own step and share it with the Bitrise community if you wish.
Individual steps accomplish only one task at a time, so you usually need to use several of them to achieve your goal. The resulting whole - the so-called workflow - is thus ultimately put together and set up to do everything we need it to do.
It's time to take a look at how to create a workflow to automatically build, test, and publish an iOS app on TestFlight. Bitrise has already created a sample workflow for us during the initial setup, and we'll use it as the basis for our own. We'll name it TestFlight.
Workflow setup: the Git repository and SSH key activation
We will delete most of the original steps in the newly created workflow, leaving only Activate SSH key and Git Clone Repository, which are necessary to download our project to the Bitrise machine.
Instalace CocoaPods
If we use CocoaPods in the project, we must not forget to install them. The step called Run CocoaPods install helps us to do this.
Unit tests starting
Before we start archiving and publishing the beta version of our application to TestFlight, it is first advisable to run a set of unit and possibly also UI tests. Automated testing will ensure that each new version does not have key parts of the application broken. This way, we don't have to spend so much time on manual testing - assuming, of course, that the tests are written correctly.
This step requires several input parameters. These include, for example, the Xcode schema and the project used for testing. The values for these parameters can be defined as variables on the Env Vars bookmark.
Archiving and publication
We certainly don't want to publish any version of the app that has been found to have bugs in testing. We'll prevent that simply by. We'll make sure we turn off the Run if previous Step failed option for all subsequent steps.
If the testing goes smoothly, we can rejoice and move on to archiving the application.
For our purposes, we'll use Fastlane, which we set up earlier. If we use the auto-signing option in Xcode, we first need to ensure that provisioning profilesare available on the machine where our workflow will run. The Manage iOS Code Signing step is useful for this, which we'll configure to use our previously added App Store Connect API key.
Then add the Set Xcode Project Build Number step. This will increase the build version for the upcoming archive and also create room for seamless adoption of the application on TestFlight.
We're finally coming to the finish line. All that's left is to run the lane of our choice using the Fastlane step and we're done. Simple, straightforward, and most importantly, efficient.
Webhook
The great charm of the CI/CD service undoubtedly lies in the convenient automation it brings us. To avoid further unnecessary manual intervention after the initial setup, we recommend setting up Webhook. This will ensure that our solution automatically starts specific workflows after a selected action in our repository (e.g. push to dev branch). How to set it up for your Git service can be found clearly on the Bitrise website.
We hope this guide will help you with your own solution! Do you have any questions? Have you encountered a problem in your project? We will be happy to help you. Contact us!
This article was prepared for you by Marcel, our iOS developer.
The control question - what are cookies? Choose the correct answer.
Cookies are not sweets, but text files
We want to have an overview of how it goes on our website. But you have the power to affect how much we know about your visit.
As application and web developers, we are very interested in analytical data, so we will be grateful for your absolute consent.
Cookies Setting
Select your preferred cookie permissions, the basic ones are necessary for operation, others we can use only with your consent.
Your personal data will be processed and information from your device (cookies, personality identifiers and other data collected) may be stored.
You can always change your mind and revoke your consent using the link in the footer of this website. For more information on the use of cookies, please visit this page.