Using Firebase Test Lab for Android with Continuous Integration Systems

You can use Firebase Test Lab for Android 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.

Using Firebase Test Lab for Android with Jenkins CI

This section describes how to use Test Lab with Jenkins CI.

Requirements

Before you can use Firebase Test Lab for Android with Jenkins, you need to complete the following steps:

  1. Set up gcloud. Follow the instructions from Using Firebase Test Lab for Android from the gcloud Command Line to create a Firebase project and configure your local Google Cloud SDK environment.
  2. Create a service account. Using a service account causes gcloud to treat the user as a program instead of treating the user as a person. This avoids checks for spam and prevents the account from being blocked or prompted for captchas. To create and activate a service account, follow the instructions for using the gcloud auth activate-service-account command.
  3. 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 for Android, configure global security settings to enforce access control and authenticate users.

To configure global security settings

  1. 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.
  2. On the Jenkins dashboard, click Manage Jenkins, and then click Configure Global Security.
  3. On the Configure Global Security page, click Enable security, and then click Save.

For more information about configuring security settings for Jenkins, see Quick and Simple Security, Standard Security Setup, and Securing Jenkins.

Create a Jenkins project

Next, create a project for running continuous integration testing of your app with Firebase Test Lab for Android.

To create a Jenkins project

  1. 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.
  2. On the Jenkins dashboard, click New Item.
  3. 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.
  4. 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.

To learn about configuring builds in Jenkins, see Configuring automatic builds.

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.

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

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

  2. 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

  1. From the main page for your project, click Configure.
  2. On the project configuration page, scroll down to the Build section, and then choose Execute shell from the Add build step menu.

  3. 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:

    gcloud firebase test android run --app <local_server_path>/<app_apk>.apk
    --test <local_server_path>/<app_test_apk>.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 for Android Results.

Continuous integration with other CI systems

To learn how to use Firebase Test Lab for Android with Circle CI, see this guide from Circle CI.

If you create documentation explaining how to use Firebase Test Lab for Android with another CI system, contact us so that we can review it for inclusion in this section.

Send feedback about...

Need help? Visit our support page.