简体   繁体   English

适用于CI / CD的Gitlab ssh配置

[英]Gitlab ssh configuration for CI/CD

I'm having issues configurating the CI/CD with ssh of Gitlab 我在使用Gitlab的ssh配置CI / CD时遇到问题

 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... 在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 ? 我读过不支持gitlab的ssh CI / CD吗? does anyone have some sugestion or an example. 有没有人提出建议或示例。

Looks like GitLab does allow for the use of SSH keys with GitLab and CI/CD. 看起来GitLab确实允许在GitLab和CI / CD中使用SSH密钥。 You can find that information here: 您可以在这里找到该信息:

SSH Keys with GitLab 使用GitLab的SSH密钥

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! 在那里,您将看到他们在关键字“ before-script”下使用SSH信息,但是我敢肯定这种事情是可延展的!

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. 看来您没有传递私钥或未将gitlab ssh密钥添加到服务器中的已知主机列表。

Try adding the before script as below and check it. 尝试如下添加前脚本并进行检查。 (Change yum commands to apt-get accordingly) (将yum命令更改为apt-get)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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