我试图将我的GitLab repo连接到我的远程ubuntu服务器,每次我对repo进行新的提交时,管道获取触发器并将最新的更改部署到我的远程服务器中 .

我相信我已成功通过 SSHhowever every time the pipeline triggers I don't see any changes on files of the remote server. 将管道连接到远程服务器

以下是我完整的 .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

我猜, the reason that I am unable to see latest changes in my remote server is because it's executing the commands inside gitlab docker image itself instead of my remote server. (Using docker image ruby:2.1)