Jenkins for Android: Deploying to Firebase, Play Console

Guneet Singh
4 min readJun 29, 2022

In the previous articles, I explained Introduction to CI/CD and its tools and Jenkins: Introduction & Setup. Now, we will see how we can deploy to Firebase App Distribution and Google PlayStore Console.

There is a very nice article on how to distribute your app to Firebase App Distribution so I won’t duplicate the content here but rather share the link to it. Please check it out.

Now moving to the next part, distributing to Play Store we have to set up our Google Play developer Account first. To publish or manage your app on the play store, Google provides a specific API. To access the said API first, we have to Link the developer console to a Google Cloud Project. To do so, you have to be the owner of the Developer Account (only the one who created the account has the said access).

As you can see, you can either link an existing Google Cloud Project or create a new one via the developer console itself.

After this step you will the below screen:

Next, we need to create a service account as we did for the Firebase with the appropriate permissions. Here you can add developer’s email ids that may have access to this service account or those who can make changes to the service account (e.g. changing permissions, adding/deleting users etc.). Please note that this service account can only be created by the owner of the Google Play Developer Account or Google cloud project (as both will be the same) i.e. the one who created the account else you have to share your google cloud project with the developers via the same service account we are creating or giving them access via IAM. You can goto the service account section of the google cloud by visiting the following :

https://console.cloud.google.com/iam-admin/serviceaccounts?orgonly=true&project=<your Google Play Console Developer project id>&supportedpurview=organizationId

You will see something like this:

Don’t forget to create and download the service key as will use it at the end of this story. Once you have created the service account the same will start appearing as in the list below:

You will also have to grant access in your developer console to the service account created like this. Here you just simply add the created service accounts to the Users and permissions page of your developer console and grant access to the apps the said service account can make changes to.

Here you can manage the operations service account can perform e.g. limiting access only to the testing channel.

Next, you will also need to enable the Google Play Android Developer API from here in order to consume it.

The last part is to use the API. We will use Gradle Play Publisher for this. For a POC configuration, all you need is to add the plugin in both the app and the project level build.gradle file and the service account key we will use as an environment variable (later). The default channel for deployment that GPP will use is internal.

// build.gradle (project level)
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.github.triplet.play' version '3.7.0' apply false
}
// build.gradle (app level)
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.github.triplet.play'
}

Before you can start deployments through pipelining you have at least one build uploaded manually else it will complain that the package not found.

Moving to the Jenkins, all we need is to add a new stage to the existing pipeline like the below:

pipeline {
agent any
//.... other stages
stage('Deploy on Playstore') {
environment {
ANDROID_PUBLISHER_CREDENTIALS = """${sh(
returnStdout: true,
script: 'cat /path/to/serviceAccount/key.json'
)}"""
}
steps {
sh '''./gradlew publishBundle'''
}
//...
}

Note that ANDROID_PUBLISHER_CREDENTIALS is taking a JSON object (i.e. the contents of the JSON file) not the path of the file.

I am dropping the repo below to recreate the project. Use the main branch for the Play Console example code and the development branch for the Firebase App Distribution example. I hope you enjoyed it.

--

--