-1

Desperate help needed:

Already asked for the case with gitlab-runner register as "shell", I try to ask a very similar question here with gitlab-runner register as "docker".

Since 3 days I try to get Gitlab CI running (using docker, fastlane - all for an iOS-app having Cocoapods dependencies).

Here is the error message that the GitLab CI spits out:

enter image description here

I did the following steps:

  1. install fastlane (link to fastlane page)

  2. create a GitLab project and upload your project repository (link to GitLab)

  3. install gitlab-runner on MacOS, following these steps...

  4. install Docker (for desktop), registering here and downloading the app

  5. register gitlab-runner (i.e. open terminal and type the following): (your Token can be found under 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. start docker application on your Mac

  2. run docker image (by typing the following in your terminal:)

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

After all that, any git push to your GitLab project repo will automatically start a Pipeline.

I also tried using a local shell (instead of docker) - but no success either as documented here.

No matter what I try, I always end up with the same error message:

enter image description 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.

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

And here the 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
iKK
  • 6,394
  • 10
  • 58
  • 131
  • Possible duplicate of [GitLab CI with Fastlane and Cocoapods not working](https://stackoverflow.com/questions/55381303/gitlab-ci-with-fastlane-and-cocoapods-not-working) – janpio Mar 28 '19 at 09:51
  • It is a very similar question, I agree. However, what is new here is the fact that I tried the gitlab ci working with Docker (which is not the case in the other entry)... – iKK Mar 28 '19 at 10:02
  • 1
    You are still running CocoaPods as root, which doesn't work as the error message tells you. Find a way not to do that (which could be via asking a question that helps you understand how this is run via sudo, how you can change that or similar). – janpio Mar 28 '19 at 13:46
  • Thank you very much for your help. I realised I did a terrible mistake by calling `sudo gitlab-runner register ...` instead of `gitlab-runner register...`. But now (leaving docker and going back to shell - since some article propose shell for iOS projects...) - I have the next problem which is a `Permission denied` error. It seems that gitlab tries to make a directory called `builds`. I did set the permissions to read&write for the location gitlab tries to mkdir. But it still does not work. Any idea on how to solve this permission issue ?? – iKK Mar 28 '19 at 13:53
  • 1
    No, as I am not going to try to understand what is going on. Create a new question that includes (only!) the relevant information and I am sure someone will be able to help you. – janpio Mar 28 '19 at 14:00
  • Thanks, I did so [here...](https://stackoverflow.com/questions/55399687/gitlab-ci-ios-project-issue-permission-denied) – iKK Mar 28 '19 at 14:21

1 Answers1

1

I finally found the solution:

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, on a Mac you absolutely need to leave sudo out and absolutely register as "shell" executor for GitLab (i.e. not "docker")

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

iKK
  • 6,394
  • 10
  • 58
  • 131