I tried @ jakub-kania's solution, but I always got it id_rsa invalid format. I think gitlab secret variables are somehow screwed up.
I made it work by directly passing the deployment key to ssh-add without creating ssh keys. Here is a working solution:
merge to master:
stage: deploy
image: alpine
only:
- dev-branch
before_script:
- apk add
- mkdir ~/.ssh
- ssh-keyscan -p 2222 <gitlab.domain.com> > ~/.ssh/known_hosts
- eval `ssh-agent -s`
- ssh-add <(echo "$GITLAB_DEPLOY_KEY")
- ssh -T git@<gitlab.domain.com> -p 2222
- git config
- git config
- git remote set-url origin ssh://git@<gitlab.domain.com>:2222/path/to/repo.git
script:
- git checkout master
- git reset
- git merge $CI_BUILD_REF
- git push origin master
source
share