Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone another GitLab repository in GitLab CI script

Tags:

gitlab

I've seen this: `git clone project2` in gitlab-ci.yml? as well as a bunch of similar posts with similar answers implying that one should use Git submodules.

Without getting into arguments about whether submodules in Git work well, in my case, that just isn't an option at all (what other project to check out depends on the arguments passed to the trigger of the job, or, at least, it should).

Another requirement is that I need to be able to track the user who started the chain of triggers. I.e. hard-coding my personal token, or just any token will not do it: I need GitLab to use the permissions of the user who executed the job in order to clone other repositories.

Short of giving up GitLab and looking for a mature CI alternative, is there any way to get this done?

like image 374
wvxvw Avatar asked Nov 20 '18 10:11

wvxvw


Video Answer


1 Answers

As New CI job permissions model states that there are 2 options: use gitlab-ci-token:${CI_JOB_TOKEN} or write it to ~/.netrc (doesn't work for me).

But we have multiple dependent repositories defined in package.json so our solution is to overwrite git config

git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@your-gitlab.com/".insteadOf "ssh://[email protected]/"
like image 51
vladkras Avatar answered Oct 02 '22 17:10

vladkras