让 GitLab CI 克隆私有存储库 [英] Getting GitLab CI to clone private repositories

查看:33
本文介绍了让 GitLab CI 克隆私有存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 GitLab 和GitLab CI 设置为托管和测试我的一些私人存储库.对于这个系统下的作曲家模块,我设置了 Satis 来解析我的私有包.

I have GitLab & GitLab CI set up to host and test some of my private repos. For my composer modules under this system, I have Satis set up to resolve my private packages.

很明显,这些私有包需要一个 ssh 密钥来克隆它们,我在终端中有这个工作 - 我可以运行 composer install 并获取这些包,只要我用 ssh-add<添加密钥/code> 在 shell 中.

Obviously these private packages require an ssh key to clone them, and I have this working in the terminal - I can run composer install and get these packages, so long as I have the key added with ssh-add in the shell.

但是,在 GitLab CI 中运行我的测试时,如果项目具有任何这些依赖项,则测试将无法完成,因为我的 GitLab 实例需要身份验证才能获取 deps(显然),并且测试失败并显示 Host key验证失败.

However, when running my tests in GitLab CI, if a project has any of these dependencies the tests will not complete as my GitLab instance needs authentication to get the deps (obviously), and the test fails saying Host key verification failed.

我的问题是如何设置它,以便在运行测试时它可以在没有密码的情况下向 gitlab 进行身份验证?我尝试在我的跑步者 ~/.ssh 文件夹中放置一个无密码的 ssh-key,但是构建甚至不会添加密钥eval ssh-agent -s" 后跟 ssh-add 似乎无法说明代理未运行...

My question is how do I set this up so that when the runner runs the test it can authenticate to gitlab without a password? I have tried putting a password-less ssh-key in my runners ~/.ssh folder, however the build wont even add the key, "eval ssh-agent -s" followed by ssh-add seems to fail saying the agent isn't running...

推荐答案

我将其发布为答案,因为其他人并不完全清楚和/或详细的恕我直言

I'm posting this as an answer since others weren't completely clear and/or detailed IMHO

从 GitLab 8.12+ 开始,假设子模块存储库与请求它的服务器位于同一服务器中,您现在可以:

Starting from GitLab 8.12+, assuming the submodule repo is in the same server as the one requesting it, you can now:

  1. 像往常一样使用 git 子模块设置 repo (git submodule add git@somewhere:folder/mysubmodule.git)

修改你的 .gitmodules 文件如下

 [submodule "mysubmodule"]
   path = mysubmodule
   url = ../../group/mysubmodule.git

其中 ../../group/mysubmodule.git 是从您的存储库到子模块的相对路径.

where ../../group/mysubmodule.git is a relative path from your repository to the submodule's one.

将以下行添加到 gitlab-ci.yml

 variables:
   GIT_SUBMODULE_STRATEGY: recursive

指示运行器在构建之前获取所有子模块.

to instruct the runner to fetch all submodules before the build.

警告:如果您的跑步者似乎忽略了 GIT_SUBMODULE_STRATEGY 指令,您可能应该考虑 更新它.

Caveat: if your runner seems to ignore the GIT_SUBMODULE_STRATEGY directive, you should probably consider updating it.

(来源:https://docs.gitlab.com/ce/ci/git_submodules.html)

这篇关于让 GitLab CI 克隆私有存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆