GitLab Runner SSH 只执行一个命令



我正在尝试使用 gitlab 设置持续部署。我正在使用贝壳转轮。我希望这个运行器将我的代码部署到其他实例。

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

.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

现在

参考 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- 这不会在远程实例中生成目录

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

现在,是编写所有以ssh开头的连续命令仅选项还是我走错了路?

正如评论中所建议的,

这个答案

最新更新