gitlabgitlab-ci-runner

Getting 'could not read Username' error in GitLab pipeline when cloning a submodule


I'm trying to create a build pipeline in GitLab for a project that has a Git submodule included in the project's repository. When the pipeline build job runs it tries to clone the submodule but fails with this error: could not read Username for 'https://gitlab.com': No such device or address

The Git submodule lives in the same GitLab group on the same instance. I already added these environmental variables to the .gitlab-ci.yml like this:

---
stages:
  - lint
  - build
  - deploy

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  GIT_SUBMODULE_FORCE_HTTPS: "true"

Here's the .gitmodules file in the project where I'm running the pipeline:

[submodule "build-tools"]
        path = build-tools
        url = https://gitlab.com/core/frontend-dev/build-tools.git

This is the project's url: https://gitlab.com/core/frontend-dev/api-service.git

Do I need to convert the submodule url to a relative url since they are both in the same GitLab instance?


Solution

  • I solved the issue. The solution is two parts.

    First you have to change the url in the .gitmodules to be relative like this:

    [submodule "build-tools"]
            path = build-tools
            url = ../build-tools.git
    

    The url is relative to the project where you are storing the .gitmodule. So if the submodule and the project are in the same group then the path would be ../

    The second part is you have to give permission to the project pipeline to access the submodule project. Go into the project settings that is being used as the submodule and find 'Token Access'. It's in 'Settings->CI/CD->Token Access'. Add the path to the project under 'Allow CI job tokens from the following projects to access this project'.