如何为Gitlab运行程序启用通过SSH克隆? [英] How do I enable cloning over SSH for a Gitlab runner?

查看:308
本文介绍了如何为Gitlab运行程序启用通过SSH克隆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Gitlab运行器上通过HTTP克隆大型存储库时遇到一些麻烦.我尝试了几种方法来进行浅层克隆或禁用克隆压缩.还是没有运气.

I am having some trouble cloning large repositories over HTTP on my Windows Gitlab runner. I've tried several methods to do shallow clones or disable clone compression. Still no luck.

通过SSH克隆相同的存储库可以很好地用作临时解决方案,我希望在我们的Gitlab CI流程中可以使用此存储库.

Cloning the same repository over SSH works great as a temporary solution and I would like to get this working on our Gitlab CI process.

现在问题出在哪里,我不知道如何使用SSH作为gitlab-multi-runner的克隆方法.它似乎只是默认使用HTTP,关于克隆,我唯一的选择是执行完全克隆还是提取.

The issue now stands where I have no idea how to use SSH as a clone method for the gitlab-multi-runner. It just seems to use HTTP as a default, and my only options regarding cloning is whether it will do a full clone or a fetch.

有人可以解释我如何通过SSH(而不是HTTP)使克隆/获取在运行程序上运行吗?

Can someone explain how I could get that clone/fetch to work on a runner over SSH instead of HTTP?

Gitlab版本:GitLab社区版8.10.7

Gitlab Version: GitLab Community Edition 8.10.7

谢谢!

推荐答案

作为gitlab的新手,我设法破解了此问题的解决方法,因为我也没有找到更改默认值的内置方法克隆过程(尽管这里是有关如何完成的最新评论).

As a newcomer to gitlab, I've managed to hack a workaround to this issue as I also haven't found a built-in way to change the default cloning process (although here is a recent comment about how it can be done).

通过禁用自动克隆过程,您可以只需在before_script中编写您自己的克隆过程即可有效地完全覆盖其行为.仅出于示例的目的,下面的内容显示了如何完成HTTP克隆,但是可以进行ssh克隆(

By disabling the automatic cloning process, you can effectively override its behavior completely by simply writing your own cloning process in a before_script. Only for the purposes of example does the below show how to accomplish this for HTTP cloning but could be adapted for ssh cloning (if you're trying to use HTTP cloning you should use the built-in cloning process and the config.toml):

  1. 创建一个名为"gitlab-runner"的新用户,并生成其用户身份验证令牌以供以后使用(或者,在您的情况下,您将生成ssh密钥).

  1. Create a new user called "gitlab-runner" and generate their user auth token for later use (or in your case, you would generate ssh keys).

通过在项目或组设置中添加以下变量来禁用运行程序的克隆过程:.../settings/ci_cd

Disable cloning process for runner by adding the following variable in either your project or group settings: .../settings/ci_cd

键:GIT_STRATEGY

key: GIT_STRATEGY

值:无

before_script克隆您的存储库,例如:

Clone your repo in a before_script such as:


before_script:
  ## clean the working directory
  - BUILD_DIR=/home/gitlab-runner/builds/$RUNNER_TOKEN/0
  - CLONE_DIR="$BUILD_DIR/$CI_PROJECT_PATH"
  - cd $BUILD_DIR
  - rm -rf $CLONE_DIR
  - mkdir -p $CLONE_DIR

  ## clone the project each time (inefficient, consider performing fetch instead if it already exists)
  - git clone http://gitlab-runner:$GITLABRUNNER_USER_AUTH_TOKEN@server:8888/${CI_PROJECT_PATH}.git $CLONE_DIR
  - cd $CLONE_DIR

注意:这是我在步骤2中也配置的相关变量,而不是在脚本中对其进行硬编码:

Note: Here are the relevant variables I also configured in step 2 rather than hard coding them in the script:

  • RUNNER_TOKEN:运行程序管理器"菜单中列出了您要运行的特定运行程序的运行程序令牌"值.
  • GITLABRUNNER_USER_AUTH_TOKEN:这是您在步骤1中生成的身份验证令牌.
  • RUNNER_TOKEN: "Runner Token" value listed in the Admin "Runners" menu for the particular runner you are trying to run.
  • GITLABRUNNER_USER_AUTH_TOKEN: This is the auth token you generated in step 1.

这篇关于如何为Gitlab运行程序启用通过SSH克隆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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