I have a very long command in .gitlab-ci.yml
file to ssh to jump host then use rsync
to sync files from my repo to destination host (it does not have public ip so I need to access it via jump host).
Here is my .gitlab-ci
:
image: ubuntu
before_script:
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client rsync git -y )'
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -e "$PRIVATE_KEY" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
SSH:
tags:
- mytag
script:
- ssh ubuntu@host "which ssh-agent || ( apt-get update -y && apt-get install openssh-client rsync git -y ) && ssh [email protected] "mkdir -p /home/ubuntu/test" && rsync /home/ubuntu/test/.gitlab-ci.yml [email protected]:/home/ubuntu/test/.gitlab-ci.yml"
The command here is so long:
ssh ubuntu@host "which ssh-agent || ( apt-get update -y && apt-get install openssh-client rsync git -y ) && ssh [email protected] "mkdir -p /home/ubuntu/test" && rsync /home/ubuntu/test/.gitlab-ci.yml [email protected]:/home/ubuntu/test/.gitlab-ci.yml"
Let me explain it:
- First it
ssh
tohost
then installrsync
if it does not exist, then it ssh to my private server192.168.1.2
and then sync my file named.gitlab-ci.yml
(the file from my repo in my Gitlab server) to foldertest
I just wonder if there is any way to break long command above to multi lines command?