Using Firebase Test Lab with Continuous Integration Systems

You can use Firebase Test Lab when developing your app using any continuous
integration (CI) system. Continuous integration systems let you automatically
build and test your app each time you check in updates to your app source code.

Create a service account. Service accounts aren't subject to spam checks
or captcha prompts, which could otherwise block your CI builds. Create a
service account with an Editor role in the
Google Cloud Platform console.

Enable required APIs. After logging in using the service account: In the
Google Developers Console API Library page,
enable the Google Cloud Testing API and Cloud Tool Results API. To
enable these APIs, type these API names into the search box at the top of the
console, and then click Enable API on the overview page for that API.

Install and set up Jenkins

You can install and set up Jenkins CI on Linux or Windows. Certain details of
this guide are specific to installing and running Jenkins CI on Linux, including
the use of slashes (/) in file paths.

To download and install Jenkins on a computer running Linux or Windows, follow
the instructions on Installing
Jenkins. After
installing Jenkins, follow the instructions on
Starting and Accessing Jenkins
to complete setup and access the Jenkins dashboard.

Configure global security settings

Jenkins does not have user authentication and access control configured when it
is first installed. Before using Jenkins with Firebase Test Lab, configure
global security settings to enforce access control and authenticate
users.

To configure global security settings

Navigate to the Jenkins dashboard on your server. To do this, browse to
http://<servername>:8080, where <servername> is the name
of the computer where you have installed Jenkins.

On the Jenkins dashboard, click Manage Jenkins, and then click
Configure Global Security.

On the Configure Global Security page, click Enable security, and
then click Save.

Create a Jenkins project

To create a Jenkins project

Navigate to the Jenkins dashboard on your server. To do this, browse to
http://<servername>:8080, where <servername> is the name
of the computer where you have installed Jenkins.

On the Jenkins dashboard, click New Item.

Type a name for your project in the Item name field:

Choose Freestyle project to create a project that uses a single build
configuration.

Choose Build multi-configuration project to create a project that
runs on multiple different build configurations. If you plan to build
your app with a variety of build configurations (multiple locales,
multiple Android API levels, etc.), then a multi-configuration project is
the best choice.

Click Save.

After your project is created, your web browser displays the main page for your
project.

Add revision control and Gradle build steps

This section describes how to integrate Jenkins with revision control systems
such as GitHub, and how to add Gradle build steps to build APK packages
from source code.

Integrating with GitHub and other revision control systems

If you use GitHub or another revision control system to manage the source code
for your app, you can configure Jenkins to run automated builds and run tests
each time updates to your app are checked in. You can also configure
Jenkins to run builds periodically.

Adding Gradle build steps to rebuild APK packages

If you use a revision control system to manage source code for your app, you
need to include a Gradle build step to create new APK binaries each time Jenkins
downloads source code from your revision control system.

Add a build step to run the following commands in the main directory for your
application:

./gradlew :app:assembleDebug
./gradlew :app:assembleDebugAndroidTest

Add a build step to use the APK package(s) created by Gradle when testing
with Test Lab. You can use this path as the
<local_server_path> in the shell script example provided below,
where <AppFolder> is the Android Studio project folder for your
app:

<AppFolder>/app/build/outputs/apk

Add Test Lab build steps to Jenkins

Now you are ready to add a build step to Jenkins to run Test Lab using
the gcloud command line.

To add a gcloud build step

From the main page for your project, click Configure.

On the project configuration page, scroll down to the Build section,
and then choose Execute shell from the Add build step menu.

In the Jenkins Execute shell command window, enter the following,
substituting <local_server_path> for the path to the sample app on
the server, <app_apk> for your app's APK, and
<app_test_apk> for your app's test APK:

Analyze test results

After Test Lab completes testing of your app, you can review test
results in the Firebase console or in a
Google Cloud storage bucket in your
project. You can also add a
gsutil command to the shell
command shown above to copy the test results data to your local computer.
To learn more, see
Analyzing Firebase Test Lab Results.

Continuous integration with other CI systems

To learn how to use Firebase Test Lab with other CI systems, check out
their docs: