CircleCI 上 MacOS 项目的 Fastlane 构建的神秘错误

Cryptic Error with Fastlane build of MacOS project on CircleCI

我在 circleCI 上使用 FastLane 构建 MacOS 项目时遇到以下错误。我可以使用 bundle exec fastlane test 在本地构建项目,因此问题似乎与 CircleCI 环境有关,但我不知道如何追踪它。当我 ssh 进入 CircleCI 时,我能够在命令行上重现它。

这是错误:

bundler: failed to load command: fastlane (/usr/local/bin/fastlane)
NoMethodError: [!] undefined method `each' for nil:NilClass
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/scan/lib/scan/runner.rb:172:in `copy_simulator_logs'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/scan/lib/scan/runner.rb:108:in `handle_results'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/scan/lib/scan/runner.rb:22:in `run'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/scan/lib/scan/manager.rb:23:in `work'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/actions/run_tests.rb:16:in `run'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/runner.rb:261:in `block (2 levels) in execute_action'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/actions/actions_helper.rb:50:in `execute_action'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/runner.rb:253:in `block in execute_action'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/runner.rb:227:in `chdir'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/runner.rb:227:in `execute_action'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/runner.rb:157:in `trigger_action_by_name'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/fast_file.rb:159:in `method_missing'
  Fastfile:26:in `block (2 levels) in parsing_binding'
  /Library/Ruby/Gems/2.6.0/gems/fastlane-2.149.1/fastlane/lib/fastlane/lane.rb:33:in `call'
            ----snip----

我的 Fastfile 看起来像这样:

default_platform :mac

platform :mac do
  before_all do
    setup_circle_ci
  end

  desc "Runs all the tests"
  lane :test do
    scan(skip_testing: "ChronosUITests")
  end

  desc "Ad-hoc build"
  lane :adhoc do
    match(type: "adhoc")
    gym(export_method: "ad-hoc")
  end
end

我的 circleci 配置是这样的:

# .circleci/config.yml
version: 2.1
jobs:
  build-and-test:
    macos:
      xcode: 11.5.0
    environment:
      FL_OUTPUT_DIR: output
      FASTLANE_LANE: test
    steps:
      - checkout
      # https://support.circleci.com/hc/en-us/articles/360044709573-Swift-Package-Manager-fails-to-clone-from-private-Git-repositories
      - run: rm ~/.ssh/id_rsa
      - run: for ip in $(dig @8.8.8.8 bitbucket.org +short); do ssh-keyscan bitbucket.org,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
      - run: for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
      # -------
      - run: bundle install
      - run:
          name: Fastlane
          command: bundle exec fastlane $FASTLANE_LANE
      - store_artifacts:
          path: output
      - store_test_results:
          path: output/scan

  adhoc:
    macos:
      xcode: 11.5.0
    environment:
      FL_OUTPUT_DIR: output
      FASTLANE_LANE: adhoc
    steps:
      - checkout
      # https://support.circleci.com/hc/en-us/articles/360044709573-Swift-Package-Manager-fails-to-clone-from-private-Git-repositories
      - run: rm ~/.ssh/id_rsa
      - run: for ip in $(dig @8.8.8.8 bitbucket.org +short); do ssh-keyscan bitbucket.org,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
      - run: for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts || true
      # -----
      - run: bundle install
      - run:
          name: Fastlane
          command: bundle exec fastlane $FASTLANE_LANE
      - store_artifacts:
          path: output

workflows:
  build-test-adhoc:
    jobs:
      - build-and-test
      - adhoc:
          filters:
            branches:
              only: development
          requires:
            - build-and-test

我发现了一个解决方案,或者至少是一个解决方法。失败的步骤是复制模拟器日志(这甚至适用于 mac 项目吗?)。无论如何,添加不包含模拟器日志的选项解决了这个问题。

scan(include_simulator_logs: false)