【问题标题】:GitLab CI with Fastlane and Cocoapods not working带有 Fastlane 和 Cocoapods 的 GitLab CI 无法正常工作
【发布时间】:2019-03-27 15:46:15
【问题描述】:

我无法让 GitLab CI 与 Fastlane 和 Cocoapods 一起使用。

这是我在 Gitlab-CI 期间收到的错误消息:

[!] You cannot run CocoaPods as root.

GitLab CI 日志截图如下:

这是我写入 MacOS 终端的 gitlab-runner 注册代码:

sudo gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --registration-token "ABCDEFG21sadfSAEGEAERE" \
  --description "MyApp runner with shell" \
  --tag-list ios \
  --executor "shell"

然后我在终端中输入:

sudo gitlab-runner start

还有……

sudo gitlab-runner run

run cmd 之后,任何 git push 都会导致 GitLab CI 启动一个新的 Pipeline。到目前为止,一切都很好:)

但是几秒钟后,出现上述错误。它与 Cocoapods 有关。

如何让 Gitlab(和/或 Fastlane)在 CI 期间识别 Podfile?

这是我的快速文件:

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

我尝试了很多其他 Podfile 路径,甚至尝试在 docker 容器上运行所有内容。但同样的事情,错误[!] 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

任何帮助表示赞赏。如何让 Podfile 被 CI 识别???

【问题讨论】:

  • "您不能以 root 身份运行 CocoaPods。" - 不要以 root 身份运行,即不要使用sudo
  • 感谢您的解释。您能否指定不​​使用sudo 的位置。你的意思是改用gitlab-runner startgitlab-runner run 吗? gitlab-runner run(没有 sudo)的问题在于,在这种情况下,CI-Pipeline 出于某种原因永远不会启动。你能举例说明你的意思吗?
  • 您不需要以管理员用户身份运行任何部分。作为正确配置/受限制的用户犯了一个错误,它可能没那么糟糕。以 root 身份执行此操作,可能会对您的机器/服务器造成严重损坏。在没有 sudo 的情况下运行所有​​内容,如果它抱怨,请调查它为什么需要它。您可能只需要更改某些文件/文件夹的所有权/访问权限
  • 如果我使用gitlab-runner run 而不是sudo gitlab-runner run,那么我最终会在我的Gitlab-CI 设置中看到New runner: Has not connected yet 消息。跑步者似乎没有启动或连接(我的终端只显示并冻结Listen address not defined)。我怎样才能让 gitlab-runner 在没有 sudo 的情况下运行??????需要设置哪些权限以及在哪里设置? (我在 MacOS 上)

标签: continuous-integration realm gitlab cocoapods fastlane


【解决方案1】:

我终于找到了解决办法:

您的gitlab-runner register 也不允许有sudo

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

无论如何,正如@Scriptable 指出的那样,在 Mac 上您绝对需要将 sudo 排除在外!

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

【讨论】:

  • 我没有以 sudo 身份运行,但仍然无法正常工作,有什么想法吗?
  • 我在 Gitlab Server CI 上遇到了这个问题,有什么解决方案吗?
【解决方案2】:

我通过添加 -user 选项解决了我的问题。喜欢

sudo gitlab-runner run -user <my_username>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 2019-02-22
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    相关资源
    最近更新 更多