ubuntu - 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 选项前置的连续命令还是我走错了路?
解决方案
正如评论中所建议的,
推荐阅读
- javascript - Javascript从数据中提取某些字符串
- sql - 根据另一个字段更新记录的动态数量
- c# - Visual Studio 上的 INSERT INTO 命令中的语法错误
- javascript - 如何在循环中动态地将新的键:值对添加到现有的 Javascript 对象
- python - 如何创建类别和子类别
- parsing - 为算术表达式定义从左到右的解析器
- python - 如何从 json 作为函数创建 json
- javascript - 使用扩展运算符填充 ReactJS 中的状态对象的匿名函数
- java - 使用 Ajax 调用将 Cordova 9 移动应用程序连接到 Java Web 服务
- c# - How to open docx file in ASP.NET MVC project using openxml for overwriting some text