I am trying to set up continuous deployment using gitlab. I am using a shell runner. I want this runner to deploy my code to some other instance.
I've correctly added pub and pvt key in the remote server and gitlab respectively. ssh is working just fine. My concern is that in the ".gitlab-ci.yml" file, only those commands are being executed on remote instance where ssh user@domain is prepended. I assumed that once I will login to remote server, all my consecutive commands should be executed there and not in the runner's env, but this is not happening.
.gitlab-ci.yml file
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
now,
REFERENCE 1 - logins to remote instance successfully. Also, connection is not closed.
$ 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 ***
REFERENCE 2 - This is not making dir in the remote instance
REFERENCE 3 - It lists all files of remote instance.
Now, is writing all the consecutive commands prepended by ssh only option or am I going down the wrong way?