简体   繁体   中英

Gitlab ssh configuration for CI/CD

I'm having issues configurating the CI/CD with ssh of Gitlab

 image: trion/ng-cli-karma cache: paths: - node_modules/ deploy_production: stage: deploy environment: Production only: - master script: - rm ./package-lock.json - npm install - cd dist/ - ls - apt-get update -qq && apt-get install -y -qq sshpass - sshpass -V - export SSHPASS=XXXX - sshpass -e scp -o stricthostkeychecking=no -r . root@IP_SERVER:/DIR:PATH 

On git push...

Warning: Permanently added 'IP_SERVER' (ECDSA) to the list of known hosts.

Permission denied (publickey).

lost connection

ERROR: Job failed: exit code 1

I had read that ssh CI/CD with gitlab is not supported yet ? does anyone have some sugestion or an example.

Looks like GitLab does allow for the use of SSH keys with GitLab and CI/CD. You can find that information here:

SSH Keys with GitLab

There you will see they use the SSH information under the keyword 'before-script' but I'm sure this sort of thing is fairly malleable!

Looks like you didn't pass your private key or didn't add the gitlab ssh key to list of known hosts in your server.

Try adding the before script as below and check it. (Change yum commands to apt-get accordingly)

before_script:
 - yum --enablerepo=epel -y install sshpass
 - yum install -y openssh openssh-client
 - eval $(ssh-agent -s)
 - ssh-add <(echo "$SSH_PRIVATE_KEY")
 - mkdir -p ~/.ssh
 - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'

script:
 - export SSHPASS= XXXX
 - sshpass -e scp -o stricthostkeychecking=no -r . $USER@$HOST:$PATH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM