无法完成Gitlab-CI工作

时间:2019-02-06 13:10:02

标签: gitlab-ci gitlab-ci-runner

我有CI设置,可将更改部署到服务器。一切正常,将更改拉到服务器,但是当所有任务结束时,运行程序仍在等待:

enter image description here

怎么了?它应该成功完成。

这是 .gitlab-ci.yml

stages:
  - deploy
before_script:
  # Setup SSH deploy keys
  - 'which ssh-agent || ( apt-get install -qq openssh-client )'
  - eval $(ssh-agent -s)
  - ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 --decode)

deploy_staging:
  type: deploy
  environment:
    name: staging
    url: example.com
  script:
    - ssh -o StrictHostKeyChecking=no root@example.com "cd public_html/gitlab-test && git checkout master && git pull origin master && exit"
  only:
    - master

更新:

输出:

Running with gitlab-runner 11.6.1 (8d829975)
  on Shared heeGPy6w
Using Shell executor...
Running on demeter...
Fetching changes...
HEAD is now at 4eaccda Update .gitlab-ci.yml
From https://git.example.com/user/ssh-test
   4eaccda..ce1729c  master     -> origin/master
Checking out ce1729c4 as master...
Skipping Git submodules setup
$ which ssh-agent || ( apt-get install -qq openssh-client )
/usr/bin/ssh-agent
$ eval $(ssh-agent -s)
Agent pid 14151
$ ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 --decode)
Identity added: /dev/fd/63 (/dev/fd/63)
$ ssh -o StrictHostKeyChecking=no root@example.com "cd public_html/gitlab-test && git checkout master && git pull origin master"
Already on 'master'
From https://git.example.com/user/ssh-test
 * branch            master     -> FETCH_HEAD
   4eaccda..ce1729c  master     -> origin/master
Updating 4eaccda..ce1729c
Fast-forward
 .gitlab-ci.yml | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
$ exit 0

此后,仍在等待...

1 个答案:

答案 0 :(得分:0)

最后,我解决了我的问题。

原因在- eval $(ssh-agent -s)行中-当我评论它时,该工作可以完成(但当然,连接不起作用)。因此,我尝试在脚本末尾添加killing命令:

- eval $(ssh-agent -k)

这是一个解决方案。现在一切正常。

最后的代码:

stages:
  - deploy
before_script:
  # Setup SSH deploy keys
  - 'which ssh-agent || ( apt-get install -qq openssh-client )'
  - eval $(ssh-agent)
  - ssh-add <(echo "$SSH_PRIVATE_KEY" | base64 --decode)

deploy_staging:
  type: deploy
  environment:
    name: staging
    url: example.com
  script:
    - ssh -o StrictHostKeyChecking=no root@example.com "cd public_html/gitlab-test && git checkout master && git pull origin master && exit 0"
    - eval $(ssh-agent -k)
  only:
    - master