在使用Jenkins搭建github流水线的时候,pipeline脚本选择从github链接导入执行总是报错
ECDSA host key is known for github.com and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
原因是因为ssh连接陌生机器需要确认,你的服务器root用户可以正常clone github代码,但是jenkins执行的时候用户是jenkins,所以要将服务器上known_hosts复制到jenkins服务账号的~/.ssh目录下
ps aux | grep jenkins
jenkins 320251 0.5 45.8 3209828 887628 ? Ssl Nov16 4:26 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
root 402926 0.0 0.0 9032 720 pts/0 S+ 11:01 0:00 grep --color=auto jenkins
cat /etc/passwd | grep jenkins
jenkins:x:111:122:Jenkins,,,:/var/lib/jenkins:/bin/bash
# 复制konws_host
cp ~/.ssh/known_hosts /var/lib/jenkins/.ssh/
问题解决
当然如果你觉得这个步骤麻烦也有另外一个不安全的做法
到系统管理–>全局安全配置里面把下边这个配置改成No verification
但是这个做法不安全