Search code examples
androidfirebaseservice-accountsgoogle-cloud-sdkfirebase-test-lab

Firebase Test lab CI upload apks


When setting up my buildserver to use Firebase Test Lab for espresso testing I keep running into the error.

ERROR: (gcloud.beta.test.android.run) Permission denied while fetching the default results bucket 
(Error 403: Access Not Configured. Cloud Tool Results API has not been used in project CLOUD_PROJECT_ID before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/toolresults/overview?project=CLOUD_PROJECT_ID then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.).
Is billing enabled for project: [PROJECT_ID]?

When I try it on my own machine which is logged in via my own account, running the command below works correctly.

gcloud beta test android run \
  --type instrumentation \
  --app app-debug.apk \
  --test app-debug-androidTest.apk \
  --device-ids Nexus4,Nexus5 \
  --os-version-ids 18,21,25 \
  --locales en \
  --orientations portrait

On my build server I want to use a service-account but when I execute the command I get the error mentioned earlier. Does anyone know what the correct way is to set this up? Does the service-account need some special role beside project editor?

In the build script I execute the commands below to authenticate and set the project before uploading the APK's

gcloud config set project PROJECT_ID
gcloud auth activate-service-account [email protected] --key-file ~/gcloud-service-key.json

Solution

  • Finally figured it out. If you want to use service accounts for Firebase Test Lab you have to enable Cloud Tool Results API which can only be enabled through Google Cloud Console and not the Firebase Console.