使用ssh获取gitlab runner 10.0.2克隆repo
我有一个gitlab安装,我正在尝试使用docker执行器设置gitlab runner。在测试开始运行之前,一切正常,但由于我的项目是私有的,并且它们没有启用http访问,因此它们在克隆时失败,原因是:使用ssh获取gitlab runner 10.0.2克隆repo,ssh,gitlab,gitlab-ci-runner,Ssh,Gitlab,Gitlab Ci Runner,我有一个gitlab安装,我正在尝试使用docker执行器设置gitlab runner。在测试开始运行之前,一切正常,但由于我的项目是私有的,并且它们没有启用http访问,因此它们在克隆时失败,原因是: Running with gitlab-runner 10.0.2 (a9a76a50) on Jupiter-docker (5f4ed288) Using Docker executor with image fedora:26 ... Using docker image sha25
Running with gitlab-runner 10.0.2 (a9a76a50)
on Jupiter-docker (5f4ed288)
Using Docker executor with image fedora:26 ...
Using docker image sha256:1f082f05a7fc20f99a4ccffc0484f45e6227984940f2c57d8617187b44fd5c46 for predefined container...
Pulling docker image fedora:26 ...
Using docker image fedora:26 ID=sha256:b0b140824a486ccc0f7968f3c6ceb6982b4b77e82ef8b4faaf2806049fc266df for build container...
Running on runner-5f4ed288-project-5-concurrent-0 via 2705e39bc3d7...
Cloning repository...
Cloning into '/builds/pmatos/tob'...
remote: Git access over HTTP is not allowed
fatal: unable to access 'https://gitlab.linki.tools/pmatos/tob.git': The requested URL returned error: 403
ERROR: Job failed: exit code 1
我已经调查过了
并决定尝试一下,因此我的.gitlab ci.yml
以以下内容开头:
image: fedora:26
before_script:
# Install ssh-agent if not already installed, it is required by Docker.
# (change apt-get to yum if you use a CentOS-based image)
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
# Run ssh-agent (inside the build environment)
- eval $(ssh-agent -s)
# Add the SSH key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
... JOBS...
image:fedora:26
在脚本之前:
#安装ssh代理如果尚未安装,Docker需要它。
#(如果使用基于CentOS的映像,请更改为转到yum)
-'哪个ssh代理| |(apt get update-y&&apt get install openssh client-y)'
#运行ssh代理(在生成环境中)
-eval$(ssh代理-s)
#将SSH_PRIVATE_key变量中存储的SSH密钥添加到代理存储
-ssh add~/.ssh/config'
... 工作。。。
我正确地设置了SSH\u私钥,等等,但问题是项目的克隆发生在脚本之前。然后我尝试用-v/home/pmatos/gitlab-runner\u ssh:/root/.ssh
启动容器,但克隆仍在尝试使用HTTP
。如何强制容器通过ssh进行克隆
然后,我尝试使用-v/home/pmatos/gitlab-runner\u ssh:/root/.ssh启动容器,但克隆仍尝试使用HTTP
如果可能,至少在容器内尝试添加
git config --global url.ssh://git@.insteadOf https://
(假设ssh用户是git
)
这将使任何https URL的克隆都使用ssh。由于gitlab CI的工作方式,CI需要
https
访问存储库。因此,如果启用CI,还需要启用https
repo访问
然而,这并不是隐私方面的问题,因为使容器
https
可访问并不会阻止gitlab检查您是否有权访问它 不幸的是,这是不可能的,因为每次gitlab runner
启动新的管道构建时,都会创建一个新的容器+1.