Clone external private submodule with deploy token from Gitlab-CI
Asked Answered
C

1

8

I have a repository repoB on a private server serverB, and get a deploy token (user + password) from it.
This repository is used as a submodule in the project I'm trying to configure.

In this project, I want to be able to init this submodule during the Gitlab-CI.

My .gitmodules is:

[submodule "repoB"]
    path = repoB
    url = https://serverB/groupB/repoB.git

And I have in my .gitlab-ci.yml:

test_build:
    variables:
        GIT_SUBMODULE_STRATEGY: recursive

Actually, the error I get is the following (group: japan7, project: nanachan, repoB: karaneko, serverB: git.inpt.fr)

Updating/initializing submodules recursively...
Synchronizing submodule url for 'karaneko'
Cloning into '/builds/japan7/nanachan/karaneko'...
fatal: could not read Username for 'https://git.inpt.fr': No such device or address
fatal: clone of 'https://git.inpt.fr/japan7/karaneko.git' into submodule path '/builds/japan7/nanachan/karenko' failed
Failed to clone 'karaneko'. Retry scheduled
Cloning into '/builds/japan7/nanachan/karaneko'...
fatal: could not read Username for 'https://git.inpt.fr': No such device or address
fatal: clone of 'https://git.inpt.fr/japan7/karaneko.git' into submodule path '/builds/japan7/nanachan/karenko' failed
Failed to clone 'karaneko' a second time, aborting
ERROR: failed: exit code 1

I suppose that I should put the deploy token user and password in the project secrets (in Settings −> CI / CD −> Variables) but I could not find the name of these variables, nor any help to solve this particular case.

How should I proceed?
Thank you in advance for your help!

Cogent answered 22/11, 2018 at 13:51 Comment(0)
S
9

I solved same issue using deploy token. Just added submodule with deploy token and everything on CI runs ok.

http://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git

And .gitmodules looks like:

[submodule "tanuki/awesome_project"]
    path = tanuki/awesome_project
    url = https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git

https://docs.gitlab.com/ee/user/project/deploy_tokens/

Slobbery answered 2/5, 2019 at 11:32 Comment(3)
But this does expose your deploy token in the super repository, right?Gap
Just found this: cutt.ly/YTt42oc I saw it from this answer: https://mcmap.net/q/1328562/-how-to-authenticate-to-a-private-github-submodule-in-a-vsts-automated-buildLannie
This partially solved my issue. The other part was that the repo wasn't able to "find" the submodule's remote no matter what I did. Adding GIT_STRATEGY: clone seemed to refresh Gitlab's refs and it works fine now.Ishmael

© 2022 - 2024 — McMap. All rights reserved.