如何将Firebase测试实验室与CircleCI集成

15

嗨,我想在Firebase测试实验室上测试我的应用程序。我想将其与CircleCI集成。我已阅读此文档https://circleci.com/docs/1.0/firebase-test-lab/并创建了config.yml。

我已经在CircleCI的环境变量中创建了 GCLOUD_SERVICE_KEY ,但它没有在Firebase测试实验室上测试应用程序。

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

有人知道我缺少什么吗?


以下所有内容从 dependencies: 开始的都是 CircleCI 1.0 语法,已经过时了。你需要将其转换为 CircleCI 2.0 语法作为第一步。 - FelicianoTech
@FelicianoTech 你能建议一下吗?我对那个不了解。 - N Sharma
有很多内容。我建议阅读配置参考文档以了解语法:https://circleci.com/docs/2.0/configuration-reference/ - FelicianoTech
你能否在这里更新文档 https://circleci.com/docs/1.0/firebase-test-lab/ ? - N Sharma
还有一个 CircleCI 论坛,可以与其他在 CircleCI 2.0 上进行 Android 构建的人讨论:https://discuss.circleci.com/ - FelicianoTech
显示剩余2条评论
1个回答

2
对于CircleCI 2.0,只有Firebase和GCP部署示例;这些示例并不真正适用于此处……gcloud部分相当相关,因为在持续集成系统中使用Firebase测试实验室的文档提到了它:
gcloud firebase test android run --app <local_server_path>/<app_apk>.apk --test <local_server_path>/<app_test_apk>.apk

在CircleCI 2.0上,gcloud命令似乎是sudo /opt/google-cloud-sdk/bin/gcloud。 此外,在此处描述了如何获取退出代码以及它们的实际含义:https://firebase.google.com/docs/test-lab/android/command-line#running_your_instrumentation_tests “未测试应用程序”的问题描述不足以说明出了什么问题。 我会假设,启动仪器测试的命令应该会抛出一些错误或投诉,请提供更多详细信息(日志)。
我刚在Medium上找到一篇文章,似乎是你要找的:关于使用Firebase测试实验室的CircleCI 2.0的所有信息(还有另一篇文章,也使用了FastLane)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接