首页 > 解决方案 > 带有 Docker、Fastlane 和 Cocoapods 的 GitLab CI 无法正常工作

问题描述

急需帮助:

已经用gitlab-runner register“shell”询问了这个案例,我尝试在这里用gitlab-runner register“docker”提出一个非常相似的问题。

从 3 天开始,我尝试让 Gitlab CI 运行(使用 docker、fastlane - 全部用于具有 Cocoapods 依赖项的 iOS 应用程序)。

这是 GitLab CI 吐出的错误消息:

在此处输入图像描述

我做了以下步骤:

  1. 安装 fastlane(链接到 fastlane 页面

  2. 创建一个 GitLab 项目并上传您的项目存储库(指向 GitLab 的链接

  3. 按照以下步骤在 MacOS 上安装 gitlab-runner ...

  4. 安装 Docker(桌面版),在此处注册并下载应用程序

  5. 注册 gitlab-runner(即打开终端并输入以下内容):(您的 Token 可以在 GitLab-->Settings-->CI/CD 下找到)

sudo gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --registration-token "TOKENABCDEFG" \
  --description "MyApp runner with ruby-2.6" \
  --tag-list ios \
  --executor "docker" \
  --docker-image ruby:2.6
  1. 在 Mac 上启动 docker 应用程序

  2. 运行 docker image (通过在终端中输入以下内容:)

docker run -d --name gitlab-runner --restart always \
  -v /Users/Shared/gitlab-runner/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

毕竟,任何对 GitLab 项目 repo 的 git push 都会自动启动 Pipeline。

我还尝试使用本地 shell(而不是 docker) - 但也没有成功,如此处所述。

无论我尝试什么,我总是会收到相同的错误消息:

在此处输入图像描述

[08:48:04]: Driving the lane 'ios tests' 
[08:48:04]: -----------------------
[08:48:04]: --- Step: cocoapods ---
[08:48:04]: -----------------------
[08:48:04]: Using deprecated option: '--clean' (true)
[08:48:04]: $ cd '.' && bundle exec pod install
[08:48:04]: ▸ WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
[08:48:04]: ▸ Consider adding the following to ~/.profile:
[08:48:04]: ▸ export LANG=en_US.UTF-8
[08:48:04]: ▸ 
[08:48:04]: ▸ bundler: failed to load command: pod (/usr/local/bundle/bin/pod)
[08:48:04]: ▸ CLAide::Help: [!] You cannot run CocoaPods as root.

这是我的.gitlab-ci.yml文件:

stages:
  - unit_tests

variables:
  LC_ALL: "en_US.UTF-8"
  LANG: "en_US.UTF-8"

before_script:
  - gem install bundler
  - bundle install

unit_tests:
  dependencies: []
  stage: unit_tests
  artifacts:
    paths:
      - fastlane/screenshots
      - fastlane/logs
  script:
    - bundle exec fastlane tests
  tags:
    - ios

这里是 Fastfile:

update_fastlane

default_platform(:ios)

platform :ios do

    def install_pods
        cocoapods(
          clean: true,
          podfile: "./Podfile",
          try_repo_update_on_error: true
        )
    end

    lane :tests do
        install_pods()
        gym(configuration: "Release",
            workspace: "MyApp.xcworkspace",
            scheme: "MyApp",
            clean: true,
            output_name: "MyApp.ipa")
        # increment_build_number
        scan(workspace: "MyApp.xcworkspace",
            devices: ["iPhone SE", "iPhone XS"],
            scheme: "MyAppTests")
    end

标签: dockerrealmgitlabcocoapodsfastlane

解决方案


我终于找到了解决方案:

gitlab-runner register是不允许有的sudo

出于某种原因,有许多教程显示不同(即使用 sudo) - 例如此视频或其他...

无论如何,在 Mac 上,您绝对需要将 sudo 排除在外,并绝对注册为 GitLab 的“shell”执行程序(即不是“docker”)

这是我找到的关于如何在 iOS 项目中使用 Gitlab CI 的最佳教程。


推荐阅读