我私人项目的大多数存储库托管在gitlab.com(托管解决方案,而不是私人托管的gitlab服务器)上的私有存储库中。这些网站托管在数字海洋VPS上。Gitlab.com CI无法登录到SSH服务器
我想使用gitlab CI在develop
分支上自动部署在测试服务器上。由于我已经在这个测试服务器上拥有一个仓库的克隆,所以自动部署的最简单的方法似乎是让gitlab-ci连接到ssh服务器,并触发git pull。
gitlab-ci.yml
我现在(ssh before_script抄自http://docs.gitlab.com/ce/ci/ssh_keys/README.html)。
deploy to test:
environment: test
only:
- develop
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 ssh key stored in SSH_PRIVATE_KEY variable to the agent store
- ssh-add <(echo "$SSH_PRIVATE_KEY")
# disable host key checking (NOTE: makes you susceptible to man-in-the-middle attacks)
# WARNING: use only in docker container, if you use it with shell you will overwrite your user's ssh config
- mkdir -p ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
script:
# Try and connect to the test server
- ssh [myname]@[mydomain.com] "cd /var/www/test.[projectname].com/ && git pull"
在gitlab管道提交上develop
结果:
$ ssh [myname]@[mydomain.com] "cd /var/www/test.[projectname].com/ && git pull"
Warning: Permanently added '[mydomain.com],[255.255.255.255]' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
ERROR: Build failed: exit code 1
我有我的本地用户对我的笔记本电脑加在gitlab的SSH_PRIVATE_KEY
变量的私钥。私钥应该可以工作,因为我可以从我的笔记本电脑连接到服务器而无需提供密码。
有没有人有这个工作,gitlab.com工作人员如何连接到SSH服务器?
嗨@vityrus,你管理使用ssh连接并执行命令在远程主机上? – BigDong