- Generate ssh key (if not exists)
ssh-keygen
- Create variable with SSH_PRIVATE_KEY and add the
~/.ssh/id_rsa
private key into it
- Add the key into authorized keys
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
- Create init section in .gitlab-ci.yml
before_script:
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- Connect and run command in one connection
ssh username@address "git fetch --all; git reset --hard origin/master; git pull origin master; ..."