Setup a Flutter CI/CD with GitLab CI — Part 5

Scripting the CD pipeline with Fastlane

Roger Tan
Kin + Carta Created
4 min readOct 8, 2019

--

GitLab CI/CD + Flutter illustrations

In the previous post, we learnt how to distribute apps using App Center.

In this article, we will describe the process for scripting CD using Fastlane.

Setting up Fastlane

Fastlane logo

Before we begin, ensure Bundler is installed on your local and CI machine.

Next step is to generate a Gemfile on your local machine. Run the following command-line:
$ bundler init

Then open and edit the Gemfile by adding the following below.

Then, install Fastlane with Bundler by running the following command line.
$ bundle install

Setting up Fastlane for Android

The next step will be to create a Fastfile for Android by running the following command lines.
$ cd android
$ bundle exec fastlane init

You will then be asked several questions which need to be answered (eg. define the package name, etc…).

Within the Fastfile, paste the following text below which will create a lane to build the APK.

Now, let’s run the following command line to build the APK.
$ bundle exec fastlane build

After the APK is created a new fastlane plugin needs to be installed so that the APK can be deployed to the App Center. Run the following command line shown below.
$ fastlane add_plugin appcenter

After installation, edit the Fastfile to add a new lane called deploy, beneath the build lane by pasting the following text (in bold).

Now, run the following command line.
$ bundle exec fastlane deploy

The APK should now be deployed to the App Center from your local machine.

You will then need to edit.gitlab-ci.yml by adding and updating the values beneath the before_script and script sections shown below (in bold).

Commit and push your changes. You will see the CI and CD pipeline running.

In the next step, we will setup iOS CI/CD which requires a little bit more work.

Setting up Fastlane for iOS

Google recommends having Fastlane for each platform (https://flutter.dev/docs/deployment/fastlane-cd)

Go to the iOS directory of your Flutter project and run the following command line below.
$ bundle exec fastlane

Fastlane will ask "What would you like to use fastlane for?".
Your answer should be "4.🛠 Manual setup - manually setup your project to automate your tasks"

Within the Fastfile, paste the following text below, this will create a lane which will build the IPA.

Don’t forget to update PROVISIONNING_PROFILES_NAME with the relevant value.

Next, edit the Fastfile by adding a new lane called deploy, beneath the build lane section by pasting the following text (in bold).

Now, commit and push the changes. You will now see the CI and CD pipeline running for iOS.

And that’s it for this series. You’ve now learnt how CI/CD works within a Flutter project.

--

--