我正在尝试将我的GitLab repo连接到我的远程ubuntu服务器,每次我对repo进行新的提交时,管道获取触发器并将最新的更改部署到我的远程服务器中。
我相信我已成功通过 SSH ,将管道连接到远程服务器,但每次管道触发时我都看不到远程服务器文件的任何变化。
以下是我完整的 .gitlab-ci.yml 文件:
stages:
- deploy
deploy_staging:
stage: deploy
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- pwd
- git reset --hard origin/mysprint
- echo "Going to deploy to staging server"
environment:
name: staging
url: http://xxxxxx.compute.amazonaws.com/
only:
- sprint1

我在SSH连接后执行git reset --hard origin/mysprint
以强制在服务器上进行git更新。
我也试过" git pull origin mysprint
"并且它是一样的。
以下是管道任务的控制台结果:
Using docker image ruby:2.1 ID=sha256:223dxxxx for build container...
Running on runner-xxxx-project-xxxx-concurrent-0 via runner-xxx-srm-xxx-xxx...
Cloning repository...
Cloning into '/builds/xxx/api/xxx'...
Checking out xxx as mysprint...
Skipping Git submodules setup
$ which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 11
$ echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
Identity added: (stdin) (rsa w/o comment)
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$ ssh-keyscan gitlab.com >> ~/.ssh/known_hosts
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
# gitlab.com SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4
$ chmod 644 ~/.ssh/known_hosts
$ pwd
/builds/xxx/api/xxx
$ git reset --hard origin/mysprint
HEAD is now at 70ef5cc update on xx.js
Job succeeded

我猜,我无法在远程服务器中看到最新更改的原因是因为它在gitlab docker image本身而不是远程服务器中执行命令。 (使用docker image ruby:2.1)