【问题标题】:GitLab CI with Docker, Fastlane and Cocoapods not working带有 Docker、Fastlane 和 Cocoapods 的 GitLab CI 无法正常工作
【发布时间】:2019-03-28 09:19:28
【问题描述】:

急需帮助:

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

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

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

我做了以下步骤:

  1. 安装 fastlane (link to fastlane page)

  2. 创建一个 GitLab 项目并上传您的项目存储库 (link to GitLab)

  3. 在 MacOS 上安装 gitlab-runner,following these steps...

  4. 安装 Docker(桌面版),registering here and downloading the app

  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 镜像(通过在终端中输入以下内容:)

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) - 但也没有成功 as documented here

无论我尝试什么,我总是得到相同的错误信息:

[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

【问题讨论】:

  • 这是一个非常相似的问题,我同意。但是,这里的新功能是我尝试了 gitlab ci 与 Docker 一起工作(在其他条目中不是这种情况)...
  • 您仍在以 root 身份运行 CocoaPods,但错误消息告诉您,这不起作用。找到一种不这样做的方法(可以通过提出一个问题来帮助您了解它是如何通过 sudo 运行的,如何改变它或类似的)。
  • 非常感谢您的帮助。我意识到我通过调用sudo gitlab-runner register ... 而不是gitlab-runner register... 犯了一个严重的错误。但是现在(离开 docker 并回到 shell - 因为有些文章建议为 iOS 项目使用 shell...) - 我有下一个问题是 Permission denied 错误。似乎 gitlab 试图创建一个名为 builds 的目录。我确实为 gitlab 尝试 mkdir 的位置设置了读写权限。但它仍然不起作用。关于如何解决此权限问题的任何想法??
  • 不,因为我不会试图了解发生了什么。创建一个包含(仅!)相关信息的新问题,我相信有人能够帮助您。

标签: docker realm gitlab cocoapods fastlane


【解决方案1】:

我终于找到了解决办法:

您的gitlab-runner register 不允许有sudo

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

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

Here is the best tutorial I have found 介绍如何在 iOS 项目中使用 Gitlab CI。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-04
    • 2020-08-12
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    • 2020-07-01
    • 1970-01-01
    相关资源
    最近更新 更多