How to integrate Firebase test lab with CircleCI?


#1

Hi I want to test my app on firebase test lab. I want to integrate it with circleci. I have read this document https://circleci.com/docs/1.0/firebase-test-lab/ and created config.yml

I have created GCLOUD_SERVICE_KEY in the environment variable of circleci but it is not testing app on firebase test lab.

config.yml

version: 2.0

defaults: &defaults
    docker:
      - image: circleci/android:api-27-alpha
    working_directory: ~/github-jobs
    environment:
      JAVA_TOOL_OPTIONS: "-Xmx1024m"
      GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dorg.gradle.workers.max=2 -Dkotlin.incremental=false"
      TERM: dumb

gcloud_config: &gcloud_config
  working_directory: ~/github-jobs
  docker:
    - image: google/cloud-sdk:latest
  environment:
    TERM: dumb

update_sdk: &update_sdk
  name: Update SDK
  command: |
    mkdir "$ANDROID_HOME/licenses" || true
    echo "d56f5187479451eabf01fb78af6dfcb131a6481e" > "$ANDROID_HOME/licenses/android-sdk-license"
    echo "84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license"
    sdkmanager "platform-tools" "platforms;android-27"

jobs:
  build:
    <<: *defaults
    steps:
      - run:
          <<: *update_sdk
      - checkout
      - restore_cache:
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}-{{ checksum  "base/build.gradle" }}-{{ checksum  "instantapp/build.gradle" }}-{{ checksum  "main/build.gradle" }}-{{ checksum  "tv/build.gradle" }}
      - run:
          name: chmod permissions
          command: chmod +x ./gradlew
      - run:
          name: Download Dependencies
          command: ./gradlew dependencies --no-daemon
      - save_cache:
          paths:
            - ~/.gradle
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}-{{ checksum  "base/build.gradle" }}-{{ checksum  "instantapp/build.gradle" }}-{{ checksum  "main/build.gradle" }}-{{ checksum  "tv/build.gradle" }}
      - run:
          name: Assemble APKs
          command: ./gradlew assemble --no-daemon
      - save_cache:
          paths:
            - ~/.gradle/caches
            - ~/.gradle/wrapper
          key: jars-{{ checksum "build.gradle" }}-{{ checksum  "app/build.gradle" }}
      - store_artifacts:
          path: app/build/outputs/apk
          destination: apks
      - store_artifacts:
          path: app/build/reports
          destination: reports
      - store_artifacts:
          path: build/dependencyUpdates
          destination: dependencyUpdates
      - store_test_results:
          path: app/build/test-results
      - persist_to_workspace:
          root: .
          paths:
            - build
            - app/build

# Google Cloud Service

export_gcloud_key: &export_gcloud_key
  run:
    name: Export Google Cloud Service key environment variable
    command: echo 'export GCLOUD_SERVICE_KEY="$GCLOUD_SERVICE_KEY"' >> $BASH_ENV
decode_gcloud_key: &decode_gcloud_key
  run:
    name: Decode Google Cloud credentials
    command: echo $GCLOUD_SERVICE_KEY | base64 -di > ${HOME}/client-secret.json

test_instrumented:
  <<: *gcloud_config
  steps:
    - *export_gcloud_key
    - *decode_gcloud_key
    - run:
        name: Set Google Cloud target project
        command: gcloud config set project dazzling-fire-5515
    - run:
        name: Authenticate with Google Cloud
        command: gcloud auth activate-service-account firebase-circleci@dazzling-fire-5515.iam.gserviceaccount.com --key-file ${HOME}/client-secret.json
    - run:
        name: Run instrumented test on Firebase Test Lab
        command: gcloud firebase test android run --type instrumentation --app app/build/outputs/apk/debug/app-debug.apk --test app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk --device model=Nexus5X,version=26,locale=en_US,orientation=portrait --environment-variables coverage=true,coverageFile=/sdcard/tmp/code-coverage/connected/coverage.ec --directories-to-pull=/sdcard/tmp --timeout 20m
    - run:
        name: Create directory to store test results
        command: mkdir firebase
    - run:
        name: Download instrumented test results from Firebase Test Lab
        command: gsutil -m cp -r -U "`gsutil ls gs://test-lab-3udbiqpdyp0d0-miwcp7d69v80m | tail -1`*" /root/workspace/firebase/
    - persist_to_workspace:
        root: .
        paths:
          - firebase
    - store_artifacts:
        path: firebase/
        destination: /firebase/

general:
  branches:
    only:
     - master # list of branches to build
     - develop

Does anyone know what I am missing ?


#3

can you check now ?


#5

See now… it is perfect


#6

OK, great. Now your question could do with a problem statement, i.e. what the issue is. You’ve got a bit of that:

That is a start, but in my view, it is not complete. What is it testing on? Is it testing on Firebase but the wrong one? Is it not connecting at all? Do you have some logs to show what is going on? Do your tests pass?


#7

It is not connecting at all. It should upload apk on firebase test lab and run app on devices to test app.


#8

As per earlier:


#9

What logs do you need ? on firebase ?

If firebase then no because I think no connectivity was established.

If I see circleci dashboard it only generate a build but not trying to upload apk on firebase test lab.


#10

Ah, I see - it should push a build to Firebase and run it remotely, but it does not push the build. OK, I imagine you’d need to find out why it does not push it. How do you know it does not upload?

Is it the gcloud firebase test android run call that should send the binary to the remote? If so, can this take extra parameters to see why it is not uploading the build?


#11

I think right now test_instrumented in circleci.yml is not executing. Do you know what changes are required for that ?


#12

Can you suggest this ? @halfer


#13

No, I don’t use this technology - sorry. If you are really stuck, would it be worth your finding a freelancer who you can pay for an hour or two of their time?


#14

I’m not too familiar with Android things myself.


#15

Looking at this question again, I think readers would need to see CI logs, and if they do not reveal anything interesting, you need to discover if there are some verbose switches on the command you are using. We’re currently guessing at the problem because there is not much detail.

This is related to my earlier question:


#16

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.