gitlab runner ssh 只执行一个命令
gitlab runner ssh executes only one command
我正在尝试使用 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 - 这不是在远程实例中创建目录
REFERENCE 3 - 它列出了远程实例的所有文件。
现在,是在编写所有以 ssh only 选项为前缀的连续命令,还是我走错了路?
根据评论中的建议,
This answer
我正在尝试使用 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 - 这不是在远程实例中创建目录
REFERENCE 3 - 它列出了远程实例的所有文件。
现在,是在编写所有以 ssh only 选项为前缀的连续命令,还是我走错了路?
根据评论中的建议,
This answer