My problem is similar to this one,
Error loading key "/tmp/.ssh/gitlab": invalid format
But I have tried all the ways and I can't get it to work. I have the SSH_PRIVATE_KEY variable set, because if I do echo in the same before_script I can see it. I have tried with a line break at the end of SSH_PRIVATE_KEY but it doesn't work.
From my local machine i can do this without problem:
export SSH_PRIVATE_KEY="-----BEGIN OPENSSH PRIVATE KEY-----
thecharsinthekey=
-----END OPENSSH PRIVATE KEY-----"
echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
Identity added: (stdin) (GitLab SSH)
My config:
image: trion/ng-cli-karma:12.2.12
cache:
paths:
- node_modules/
before_script:
- which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )
- mkdir -p ~/.ssh
- echo $SSH_PRIVATE_KEY | tr -d '\r' > ~/.ssh/gitlab
- chmod 700 ~/.ssh/gitlab
- eval $(ssh-agent -s)
- ssh-add ~/.ssh/gitlab
- ssh-keyscan $VM_IPADDRESS >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
deploy_qa:
stage: deploy
environment: Staging
only:
- master
script:
- rm ./package-lock.json
- cd /my/app/dir
- ls
- scp -o stricthostkeychecking=no -r . $SSH_USER@$VM_IPADDRESS:/home/user/my/app/dir