1

I can't get GitLab CI to work with Fastlane and Cocoapods.

Here is the error messages I get during the Gitlab-CI:

enter image description here

[!] You cannot run CocoaPods as root.

Here the screenshot of the GitLab CI Log:

enter image description here

enter image description here

Here is my gitlab-runner register code that I write into a MacOS Terminal:

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

After that I type inside the terminal:

sudo gitlab-runner start

and...

sudo gitlab-runner run

After the run cmd, any git push will cause the GitLab CI to start a new Pipeline. So far, so good :)

But after a few seconds, the above error occurs. And it has to do with the Cocoapods.

How can you make Gitlab (and/or Fastlane) to recognise the Podfile during CI ??

Here is my 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

I tried plenty of other Podfile paths, and even tried to run everything on a docker container. But same thing, the error [!] You cannot run CocoaPods as root remains. What is wrong here ??

Here is my .gitlab-ci.yml file:

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

Any help appreciated. How do you make the Podfile being recognised by the CI ???

iKK
  • 6,394
  • 10
  • 58
  • 131
  • 1
    "You cannot run CocoaPods as root." - Dont run as root i.e. dont use `sudo` – Scriptable Mar 27 '19 at 15:52
  • Thank you for the explanation. Can you please specify where not to use `sudo`. Do you mean to use `gitlab-runner start` and `gitlab-runner run` instead ?? The problem with `gitlab-runner run` (without sudo) is that in this case, the CI-Pipeline never starts for some reason. Can you make an example of what you mean exactly ? – iKK Mar 27 '19 at 16:02
  • You shouldn't need to run any part of this as an admin user. Make a mistake as a correctly configured/restricted user and it might not be that bad. do it as root and you could cause serious damage to your machine/server. run everything without sudo and if it complains, investigate why it needs it. You might just need to change ownership/access permissions on certain files/folders – Scriptable Mar 27 '19 at 19:25
  • If I do `gitlab-runner run` instead of `sudo gitlab-runner run` then I end up with a the message `New runner: Has not connected yet` on my Gitlab-CI-settings. The runner does not seem to start or connect (and my Terminal only shows and freezes with `Listen address not defined`). How can I get the gitlab-runner to run without sudo ????? What permissions need to be set and where? (I am on MacOS) – iKK Mar 28 '19 at 07:53

2 Answers2

2

I resolved my problem by adding -user option. Like

sudo gitlab-runner run -user <my_username>

Thanh Vu
  • 1,599
  • 10
  • 14
1

I finally found the solution:

Also your gitlab-runner register is not allowed to have sudo.

For some reason there are many tutorials out there that show differently (i.e. with sudo) - such as this video or others...

Anyway, as @Scriptable pointed out, on a Mac you absolutely need to leave sudo out !

Here is the best tutorial I have found on how to Gitlab CI an iOS project.

iKK
  • 6,394
  • 10
  • 58
  • 131