Flutter Android — CI/CD using Jenkins and Firebase App Distribution: Part 2

In the previous post, we had configured all the necessary tools and dependencies on the Linux server and created the Flutter application with the Jenkins pipeline.
In this story, we will learn how to publish the Flutter app to Firebase App Distribution.

· Prerequisites
· Overview
∘ What is Firebase App Distribution?
∘ Key capabilities
· Set Up Firebase App Distribution
∘ Create a project in Firebase
∘ Register your app with Firebase
∘ Create Testers
· Integrating Firebase App Distribution with Jenkins
∘ Set up Firebase CLI
∘ Flutter Jenkins Pipeline CI
· Testing
· Conclusion
· References

Prerequisites

This is the list of all the prerequisites for this part 2:

  • Flutter project that you want to distribute to QA in Firebase
  • All steps in Part 1 must be completed
  • Access to the Firebase console
  • NodeJs installed

Overview

What is Firebase App Distribution?

Firebase App Distribution is a powerful platform that simplifies the process of distributing pre-release versions of an app to testers or client team members. It allows us to share an app with a specific audience for testing purposes before releasing it to the public.

Key capabilities

  • Cross-platform: Manage both your iOS and Android pre-release distributions from the same place.
  • Fast distributions: Get early releases into your testers’ hands quickly, with fast onboarding, no SDK to install, and instant app delivery.
  • Fits into your workflow: Distribute builds using the Firebase console, the Firebase Command Line Interface (CLI) tool, Fastlane, or Gradle (Android). Automate distribution by integrating the CLI into continuous integration (CI) jobs.
  • Tester management: Manage your testing teams by organizing them into groups. Easily add new testers with email invitations that walk them through the onboarding process. View the status of each tester for specific versions of your app, which indicates who has accepted a testing invitation and downloaded the app. Enable in-app feedback to make it easier to collect feedback on your pre-release apps from testers.
  • Works with Android App Bundles: Distribute releases to testers for your Android App Bundle in Google Play. App Distribution integrates with Google Play’s internal app-sharing service to streamline your app testing and launching processes.
  • Works with Crashlytics: When combined with Crashlytics, get insights into the stability of your test distributions

Set Up Firebase App Distribution

Create a project in Firebase

To create a new project in Firebase, we will go to the Firebase console’s project overview and click on Add Project. Next, we give the project a name and click on continue. Here we can choose if we want Google Analytics for our project or not, and after that, we click on Create Project.

Register your app with Firebase

To use Firebase in your Android app, you need to register your app with your Firebase project. Registering your app is often called adding your app to your project.

Create Testers

Open your Firebase console and navigate to App Distribution

In the Testers & Groups Tab, let’s add a group called “team-qa”, and add all testers’ email in this group.

Integrating Firebase App Distribution with Jenkins

Set up Firebase CLI

Install the Firebase CLI via npm by running the following command:

$ npm install -g firebase-tools

Then, Run firebase login:ci (Generate an authentication token for use in non-interactive environments.)

Flutter Jenkins Pipeline CI

Go to Jenkins > Manage Jenkins > Configure System > Global Properties > Check Environment Variables and Add the FIREBASE_TOKEN as the name, and the token created previously.

We also need to add the Firebase App ID as an environment variable. We can find it in the Firebase Console, on the General Settings page.

The last step is to edit the Jenkinsfile of the previous part to use the Firebase app distribution.

Here is the full content of Jenkinsfile.

pipeline{
agent any

environment {
PATH = "$PATH:/snap/bin"
}

options {
timestamps()
disableConcurrentBuilds()
// Timeout counter starts AFTER agent is allocated
timeout(time: 30, unit: 'MINUTES')
// Keep the 10 most recent builds
buildDiscarder(logRotator(numToKeepStr: '10'))
}

stages {
stage('Checkout code') {
steps {
git branch: 'main', url: 'https://github.com/anicetkeric/flutter_firebase_distribution.git'
}
}
stage('Get app version') {
steps {
script {
APP_VERSION = sh(returnStdout: true, script: "cat pubspec.yaml | grep version: | awk '{print \$2}'").trim()
}
}
}


stage('dependencies') {
steps {
sh '''
flutter pub get
'''
}
}

stage('Build') {
steps {
sh "flutter build apk --build-name=${APP_VERSION} --build-number=${BUILD_NUMBER}"
}
}

stage('Deploy to Firebase App Distribution') {
steps {
sh '''
firebase appdistribution:distribute build/app/outputs/flutter-apk/app-release.apk \
--app $FIREBASE_APP_ID --token $FIREBASE_TOKEN \
--release-notes "Bug fixes and improvements" --groups "team-qa"
'''
}
}

stage('Cleanup') {
steps {
sh "flutter clean"
}
}
}

post {
always {
echo 'build have finished'
}

success {
echo 'Success message'
}

failure {
echo 'Failed :( message'
}

changed {
echo 'Things were different before...'
}

aborted {
echo "Aborted message"
}
}
}

Thefirebase appdistribution:distribute command upload the app and distribute it to testers.

Testing

Build the Job Pipeline

Blue Ocean View

App Distribution emails the tester an invitation with instructions on installing and testing the build.

After opening an invitation to test an app, we can sign in with any Google account to accept the invitation, not just the account to which the invitation was originally sent. Once the invitation is accepted, we can install the test app. You also receive build notification emails from Firebase when the app’s developer distributes a new build and includes you as a tester.

Firebase App Distribution screens

The new app version is downloaded and added to your device’s home screen.

The developer can also access pending invitations and feedback.

Conclusion

Well done !!. This story builds the Flutter app and distributes Android APK to testers using the Jenkins pipeline and Firebase App Distribution.

The complete source code is available on GitHub.

You can reach out to me and follow me on MediumTwitterGitHubLinkedln

Support me through GitHub Sponsors.

Thanks for reading!

References

👉 Link to Medium blog

Related Posts