首页 > 解决方案 > gitlab runner ssh 只执行一个命令

问题描述

我正在尝试使用 gitlab 设置持续部署。我正在使用 shell 跑步者。我希望这个跑步者将我的代码部署到其他实例。

我已经分别在远程服务器和 gitlab 中正确添加了 pub 和 pvt 密钥。ssh 工作得很好。我担心的是,在“.gitlab-ci.yml”文件中,只有那些命令在远程实例上执行,其中 ssh user@domain 是前置的。我假设一旦我登录到远程服务器,我所有的连续命令都应该在那里执行,而不是在跑步者的环境中,但这并没有发生。

.gitlab-ci.yml 文件

before_script:
  - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - echo "$PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
  - mkdir -p ~/.ssh
  - chmod 700 ~/.ssh
  - ssh-keyscan ip-address >> ~/.ssh/known_hosts
  - chmod 644 ~/.ssh/known_hosts
  - ssh  user@ip-address          #REFERENCE 1
  - mkdir testing-auto-success    #REFERENCE 2
  - ssh user@ip-address ls        #REFERENCE 3

现在,

REFERENCE 1 - 成功登录远程实例。此外,连接没有关闭。

$ ssh  user@ip
Pseudo-terminal will not be allocated because stdin is not a terminal.
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-1036-gcp x86_64)


  System information as of Thu Aug 29 16:13:12 IST 2019

  System load:  0.08               Processes:           114
  Usage of /:   3.5% of 193.66GB   Users logged in:     0
  Memory usage: 31%                IP address for ens4: xx.xxx.xx.x
  Swap usage:   0%

 * Ubuntu's Kubernetes 1.14 distributions can bypass Docker and use containerd
   directly, see -containerd or try it now with

     snap install microk8s --classic

 * Canonical Livepatch is available for installation.
   - Reduce system reboots and improve kernel security. Activate at:
     https://ubuntu.com/livepatch

80 packages can be updated.
0 updates are security updates.


*** System restart required ***

参考 2 - 这不是在远程实例中创建 dir

参考 3 - 它列出了远程实例的所有文件。

现在,是写所有由 ssh only 选项前置的连续命令还是我走错了路?

标签: ubuntusshgitlabcontinuous-deploymentgitlab-ci-runner

解决方案


正如评论中所建议的,

这个答案


推荐阅读