简体   繁体   English

如何为 GitLab CI 克隆私有子模块 GitHub

[英]How clone private submodule GitHub for GitLab CI

I have follow situation: I am doing GitLab CI with private submodule from GitHub, and getting next messages in my pipeline:我有以下情况:我正在使用来自 GitHub 的私有子模块执行 GitLab CI,并在我的管道中获取下一条消息:

fatal: could not read Username for 'https://github.com': No such device or address fatal: clone of 'https://github.com/username/project' into submodule path '/my_gitlab_username/my_gitlab_project' failed致命:无法读取“https://github.com”的用户名:没有这样的设备或地址致命:将“https://github.com/username/project”克隆到子模块路径“/my_gitlab_username/my_gitlab_project”失败

fatal: could not read Username for 'https://github.com': No such device or address fatal: clone of 'https://github.com/username/project' into submodule path '/my_gitlab_username/my_gitlab_project' failed致命:无法读取“https://github.com”的用户名:没有这样的设备或地址致命:将“https://github.com/username/project”克隆到子模块路径“/my_gitlab_username/my_gitlab_project”失败

Failed to clone 'submodule_name' a second time, aborting第二次克隆 'submodule_name' 失败,中止

How can I set token or something helpful for cloning GitHub private repo?如何设置令牌或有助于克隆 GitHub 私人仓库的东西?

To clone repository, you might need to use token:要克隆存储库,您可能需要使用令牌:

git config --global credential.helper store git 配置 --global credential.helper 存储

git clone https://your_username:your_github_token@github.com/username/private-repo.git git 克隆 https://your_username:your_github_token@github.com/username/private-repo.git

Otherwise use curl api calls否则使用 curl api 调用

Docs taken from gitlab文档取自gitlab

When you use Git submodules, your project should have a file named .gitmodules .当您使用 Git 子模块时,您的项目应该有一个名为.gitmodules的文件。 You might need to modify it to work in a GitLab CI/CD job.您可能需要对其进行修改以在 GitLab CI/CD 作业中工作。

For example, your .gitmodules configuration might look like the following if:例如,您的.gitmodules配置可能如下所示:

Your project is located at https://gitlab.com/secret-group/my-project .您的项目位于https://gitlab.com/secret-group/my-project Your project depends on https://gitlab.com/group/project , which you want to include as a submodule.您的项目依赖于https://gitlab.com/group/project ,您希望将其作为子模块包含在内。 You check out your sources with an SSH address like git@gitlab.com:secret-group/my-project.git .您使用 SSH 地址(例如git@gitlab.com:secret-group/my-project.git查看您的来源。

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

When your submodule is on the same GitLab server, you should use relative URLs in your.gitmodules file.当您的子模块位于同一 GitLab 服务器上时,您应该在 .gitmodules 文件中使用相对 URL。 Then you can clone with HTTPS in all your CI/CD jobs.然后,您可以在所有 CI/CD 作业中使用 HTTPS 进行克隆。 You can also use SSH for all your local checkouts.您还可以使用 SSH 进行所有本地结帐。

The above configuration instructs Git to automatically deduce the URL to use when cloning sources.以上配置指示 Git 在克隆源时自动推导出 URL 使用。 Git uses the same configuration for both HTTPS and SSH. Git 对 HTTPS 和 SSH 使用相同的配置。 GitLab CI/CD uses HTTPS for cloning your sources, and you can continue to use SSH to clone locally. GitLab CI/CD 使用 HTTPS 克隆您的源,您可以继续使用 SSH 进行本地克隆。

For submodules not located on the same GitLab server, use the full URL:对于不在同一 GitLab 服务器上的子模块,请使用完整的 URL:

[submodule "project-x"]
  path = project-x
  url = https://gitserver.com/group/project-x.git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM