Gitlab-ci阶段未完成构建失败

时间:2019-09-05 14:19:14

标签: android continuous-integration gitlab-ci

我让gitlab ci处理单元测试(无论它们是否失败)和仪器测试(当它们不失败时),但是当./gradlew connectedAndroidTest由于某个测试失败而失败时,该命令似乎不返回任何内容给gitlab ci,因此gitlab ci等到超时。

我已经在./gradlew connectedAndroidTest命令上尝试过参数,但是没有任何作用。

stages:
  - tests
  - cleanup
  - quality #not used here
  - distribute #not used here

unit:
  stage: tests
  before_script:
    - bundle install
  script:
    - bundle exec fastlane unit_tests
  only:
    - master
    - tags
  tags:
    - cimacmini
  artifacts:
    name: "reports_${CI_PROJECT_NAME}_${CI_BUILD_REF_NAME}"
    expire_in: 60 days
    paths:
      - app/build/reports/tests/

instrumentation:
  stage: tests
  only:
    - master
    - tags
  tags:
    - cimacmini
  script:
    - emulator @instrumentation &
    - android-wait-for-emulator.sh
    - adb devices
    - adb shell settings put global window_animation_scale 0 &
    - adb shell settings put global transition_animation_scale 0 &
    - adb shell settings put global animator_duration_scale 0 &
    - adb shell input keyevent 82 &
    - ./gradlew --status
    - ./gradlew connectedAndroidTest --continue
    - stop-emulators.sh
  artifacts:
    name: "reports_${CI_PROJECT_NAME}_${CI_BUILD_REF_NAME}"
    expire_in: 60 days
    paths:
      - app/build/reports/androidTests/connected/

closeemulators:
  stage: cleanup
  only:
    - master
    - tags
  tags:
    - cimacmini
  script:
    - stop-emulators.sh
  when: always

因此,如果某些工具测试失败,则不会调用stop-emulators.sh。并非来自instrumentation步骤,也并非来自closeemulators步骤。 gitlab控制台显示以下内容:

  

在6m 17s内失败

     

58个可执行任务:58个已执行

并一直等待(直到强制超时)。有人知道该怎么做吗?

1 个答案:

答案 0 :(得分:0)

在开发UI集成测试期间,我们偶然发现了同样令人难以置信的问题。出现这种情况的原因是,当您要求gitlab执行脚本时,它将监视该脚本中已启动的所有进程,并且它将等待它们完成以完成此步骤。其中一个步骤是启动模拟器。

在测试失败的情况下,stop-emulators.sh不会执行,因为对于gitlab ./gradlew connectedAndroidTest --continue来说,这是整个管道失败的指示,它正在等待模拟器停止。但是仿真器不会停止,因为停止仿真器的下一步将根本不会执行。这是一种僵局,可以解决超时问题。

如果您登录到运行测试的计算机并手动终止模拟器,您将看到管道将被解除阻塞,并且gitlab将完成执行,并报告测试错误。

解决方案是将./gradlew connectedAndroidTest --continue移至after_script的{​​{1}}部分,该部分在失败构建之后也要执行。

文档:https://docs.gitlab.com/ee/ci/yaml/#before_script-and-after_script