Setup a Flutter CI/CD with GitLab CI — Part 4
Distributing beta apps to App Center
In the previous post, we learnt how to run tests and build apps for both platforms.
In this post. We will learn how to distribute our app via a beta distribution platform using our CD pipeline.
Beta distribution platforms are used to reduce the pain point by identifying early issues within the software development process. This is done by deploying the app to beta/internal testers before a production release to the general public.
Distributing your Flutter app using App Center
There are different ways to deploy Android & iOS apps using AppCenter (https://docs.microsoft.com/en-us/appcenter/distribution/uploading).
To begin, use these instructions to install AppCenter on the CI machine.
When you have finished, go to App Center and generate our API Token from this page which is needed to distribute our apps. Please save the token at a secure location as you won’t be able to see it again.
Next, copy the token to be used as an environment variable for the GitLab runner.
To do this, return to your GitLab repository settings pages > CI/CD > Variables.
Create a new key APPCENTER_API_TOKEN
then paste the API token into the value field. This token will be used for the purpose of authentication within App Center.
Next, edit the gitlab.yml
from your local machine and add the value deploy
under the stages
heading, as shown in the example below (in bold).
stages:
- test # All jobs related for testing such as Unit Test
- build
- deploy
Next, beneath theflutter_build_ios
lane, paste the following example (in bold)
####
#### Unit test and flutter build android or iOS
####deploy_ios:
stage: deploy
dependencies:
- flutter_build_ios
script:
- appcenter login --token $APPCENTER_API_TOKEN
- appcenter distribute release -f ios/build/Runner.ipa -g Collaborators --app [username]/[project]
tags:
- flutter
deploy_ios
is our job for deploying the iOS build to App Center.dependencies
this a keyword used to indicate the current job is dependent on another which isflutter_build_ios
defined on the previous post. This enable us to reuse the artefacts generated from the previous job.script
has a list of command lines:appcenter login --token ...
used for authentication in App Center using the token from the environment variable$APPCENTER_API_TOKEN
.- appcenter distribute release ...
used to distribute our IPA to App Center.
It’s important to specify the correct value of [username] and [project] within the App Center project.
These values can be found in the URL of the browser of your project.
Example:
https://appcenter.ms/users/JohnDoe/apps/ExampleApp
where JohnDoe
is our username and ExampleApp
our project.
Next step, repeating the above for Android apps, paste the following example (in bold)
deploy_android:
stage: deploy
dependencies:
- flutter_build_android
script:
- appcenter login --token $APPCENTER_API_TOKEN
- appcenter distribute release -f build/app/outputs/apk/release/app-release.apk -g Collaborators —app [username]/[project]
tags:
- flutter
Finally, we commit and push our updated .gitlab-ci.yml
config to the repository. You should now see builds distributed to App Center.
In the next article, we will describe the process for scripting CD using Fastlane.