Setting up Firebase App Distribution With Automatic Builds from Jenkins

Seetha Annamraju
Jan 18, 2020 · 5 min read
Photo by Adam Wilson on Unsplash

Are you currently using Fabric Beta and wondering how to migrate to Firebase App Distribution using Jenkins Pipeline and allow builds to be distributed easily?

Or do you want to set up Firebase App Distribution from scratch?

This post walks you step-by-step through how to get your builds to Firebase App Distribution using Jenkins, and have builds sent out to testers.

If you have not yet migrated your app from Fabric to Firebase, I recommend checking out this post.

Before you get started, make sure you have the following:

  • Access to your Jenkins build server.
  • Access to Fabric/Firebase project

I’m largely basing this post off of this page: Distribute with Gradle. We use Jenkins Pipeline, and this post is written in that context.

Let’s get started!

Step 1: Set up dependencies.

apply plugin: 'com.google.firebase.appdistribution'

2. Inside the buildscript block, add your firebase-appdistribution dependency. Here’s the entire buildscript block:

buildscript {
repositories {
google()
}
dependencies {
classpath 'com.google.firebase:firebase-appdistribution-gradle:1.3.1'
}
}

Step 2: Set up a Service Account for authentication.

  1. Go to Firebase Console and select your project.
  2. Click on project settings on the left top corner.

3. Select “Service Accounts” from the tab, and choose the “Manage service account permissions” link.

4. Select “CREATE SERVICE ACCOUNT” in this view, and you will see a screen that looks like this:

Fill in the details and press CREATE.

5. You will see a screen to give Service account permissions (optional). Here, select a role that is Firebase Quality Admin. This gives access to the Firebase Quality products, including App Distribution.

Press Continue when you’re done.

6. The last step here is to choose “CREATE KEY” and download the JSON file. This JSON File is the service credentials file that we need in the next step, and it will help authenticate Jenkins for automatic builds for App Distribution. Keep this file safe! You may want to rename it to something like service-credentials-projectname.json

Step 3: Set up your testers in Firebase.

You can set up your testers individually, or as a group. In my scenario, I’ve created a group called velos_testers and added a few testers.

You will refer to this group in the build.gradle file in the next step.

Step 4: Set up the Service Account credentials file locally.

Authenticating with a service account allows you to flexibly use the plugin with your continuous integration (CI) system. There are two ways to provide service account credentials:

1. Pass your service account key file to build.gradle. You might find this method convenient if you already have your service account key file in your build environment.

2. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to point to your service account key file. You might prefer this method if you already have ADC configured for another Google service (e.g., Google Cloud Platform).

Option #1 is great for setting up and testing if builds are going through when running

./gradlew assembleRelease appDistributionUploadRelease

on your local machine.

Option #2 (Step 4) is what we will eventually need to get automatic builds from Jenkins.

We will start with Option #1 to make sure everything is set up properly.

  1. Add your service-credentials-projectname.json file to the root-level of the project (at the same level as app/ and settings.gradle). Make sure to add the file to .gitignore if you don’t wish to push the file to your repository.
  2. Add firebaseAppDistribution details to app/build.gradle.

You can read about this setup here.

For our scenario, I’ve just set up app/build.gradle to distribute the release build to testers.

firebaseAppDistribution {
releaseNotes = "Test Notes"
serviceCredentialsFile = "$rootDir/seasonal-android-firebase.json"
groups=”velos_testers”
}

You should now be able to run

./gradlew assembleRelease appDistributionUploadRelease

in your Terminal, and see that a build showed up in Firebase App Distribution under the “Distributions” tab.

*Note: Test users will not receive an email every time a new build is published.

Step 5: Use Firebase App Distribution to distribute Jenkins builds.

Now, it’s time to configure Jenkins Pipeline to distribute builds to your tester group through Firebase.

  1. SSH into your Jenkins server, and add the credentials file at an appropriate location. (You may instead want to create a new key for Jenkins and use that file on the Jenkins server).

Make sure that the file has read access.

2. Set the environment variable, GOOGLE_APPLICATION_CREDENTIALS. This is what Firebase uses when looking for the credentials file.

There is more information on this here.

export GOOGLE_APPLICATION_CREDENTIALS=/absolute/path/to/credentials/file.json

3. Modify Jenkinsfile to configure two things:

  • Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the credentials file you previously uploaded.
  • Run the gradle app distribution command: ./gradlew assembleRelease appDistributionUploadRelease

The Jenkinsfile for our sample project looks like this:

The important part is to make sure that the

GOOGLE_APPLICATION_CREDENTIALS

variable is being set, and adding

./gradlew assembleRelease appDistributionUploadRelease

as part of the distribution phase.

4. Make sure you modify the app/build.gradle file to use the new GOOGLE_APPLICATION_CREDENTIALS environment variable in place of the local credentials file:

firebaseAppDistribution {
releaseNotes = "Test Notes"
serviceCredentialsFile = System.getenv("GOOGLE_APPLICATION_CREDENTIALS")
groups=”velos_testers”
}

At this point, you can remove the local credentials file completely if you are only distributing builds through Jenkins.

And that’s it! I hope this tutorial was useful for you in getting your Firebase App Distribution running with Jenkins.

Is there something you did differently? Share it in the comments!

Velos Mobile

We are a group of technologists who are passionate about…

Seetha Annamraju

Written by

Android developer, traveler, mentor, vegan foodie.

Velos Mobile

We are a group of technologists who are passionate about creating excellent mobile experiences. We’ve been doing this for a long time, and we love sharing our expertise from the first wireframe to the last bug. Check us out at www.velosmobile.com

Seetha Annamraju

Written by

Android developer, traveler, mentor, vegan foodie.

Velos Mobile

We are a group of technologists who are passionate about creating excellent mobile experiences. We’ve been doing this for a long time, and we love sharing our expertise from the first wireframe to the last bug. Check us out at www.velosmobile.com

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store