GitLab Flutter CI 失败 "tojunit: command not found"

GitLab Flutter CI fails with "tojunit: command not found"

我正在使用以下 .gitlab-ci.yml 文件 运行 使用 junit 进行测试并将报告导出为 XML 工件:

image: cirrusci/flutter:stable

before_script:
  - flutter pub get
  - flutter clean
  - flutter --version

stages:
  - analyze-and-test

analyze-and-test:
  stage: analyze-and-test
  script:
    - flutter build aot
    - flutter analyze
   # - flutter test
    - flutter test --machine | tojunit -o report.xml
  artifacts:
    when: always
    reports:
      junit:
        - report.xml
  only:
    - master
    - merge_requests

该应用程序具有以下包依赖项:

dependencies:
  flutter:
    sdk: flutter
  junitreport: ^1.3.1

当此管道为 运行 时,出现以下错误:

$ flutter test --machine | tojunit -o report.xml
/usr/bin/bash: line 139: tojunit: command not found
Unhandled exception:
FileSystemException: writeFrom failed, path = '' (OS Error: Broken pipe, errno = 32)

我正在尝试找出失败的原因。由于在调用 analyze-and-test 之前在 before_script 节中检索到包,因此应该可以找到该命令。我错过了什么?

CI 机器上似乎没有安装 tojunit。根据 junitreport installation instruction 你应该 运行 这个命令来下载程序并使启动脚本可用:

pub global activate junitreport

所以首先将此命令添加到 before_script 阶段:

before_script:
 - flutter pub get
 - flutter clean
 - flutter --version
 - flutter pub global activate junitreport

尝试运行这个。

接下来,如果 {dart-cache}/bin 目录不在您的路径中,您将收到警告,包括有关如何修复它的提示。在这种情况下,您需要向 before_script.

添加更多命令(来自提示)