Jenkins使用Git部署密钥构建 [英] Jenkins Build Using Git with Deploy Key

查看:273
本文介绍了Jenkins使用Git部署密钥构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这个git插件添加到了Jenkins。我已经生成了一个公钥,作为构建服务器上的jenkins用户。我将这个密钥添加为github的部署密钥。我已经添加了jenkins名称和电子邮件的全球git属性,并且电子邮件与公钥的末尾匹配。



当詹金斯试图从git仓库(托管在Github)我得到以下内容:

$ pre $ 由用户匿名启动
在工作区中构建/ var / lib / jenkins / jobs /测试部署/工作区
签出:工作区/ var / lib / jenkins / jobs /测试部署/工作区 - hudson.remoting.LocalChannel@9ba3afe
使用策略:默认
克隆远程Git仓库
克隆仓库源
错误:克隆远程仓库'origin'时出错:无法克隆git@github.com:GenRocket / GenRocket.git
hudson.plugins.git .GitException:无法克隆git@github.com:GenRocket / GenRocket.git
在hudson.plugins.git.GitAPI.clone(GitAPI.java:245)
at hudson.plugins.git.GitSCM $ 2.invoke(GitSCM.java:1121)
at hudson.plugins.git.GitSCM $ 2.invoke(GitSCM.java:1063)
at hudson.FilePath。 act(FilePath.java:839)
at hudson.FilePath.act(FilePath.java:821)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1063)
在hudson.model.AbstractProject.checkout(AbstractProject.java:1218)
at hudson.model.AbstractBuild $ AbstractRunner.checkout(AbstractBuild.java:586)
at hudson.model.AbstractBuild $ AbstractRunner.run (AbstractBuild.java:475)
at hudson.model.Run.run(Run.java:1438)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:239)
引起:hudson.plugins.git.GitException:命令 git clone --progress -o origin git@github.com:GenRocket / GenRocket.git / var / lib / jenkins / jobs / Test Deployment / workspace返回状态码128:
stdout:克隆到/ var / lib / jenkins / jobs /测试部署/工作区...

stderr:主机密钥验证失败。
致命:远程终端意外挂起

不知道问题是什么或者我是什么忘记了关于配置的问题。任何帮助表示赞赏。让我知道你是否需要更多的细节。

解决方案

尝试将github添加到jenkins用户的.ssh / known_hosts文件中。如果您手动尝试克隆为jenkins用户,则应提示您将github.com添加为已知主机。一旦你这样做,jenkins应该能够在构建时验证主机密钥。


I added the git plugin to Jenkins. I've generated a public key as the jenkins user on the build server. I added this key as a Deploy Key to github. I've added the global git properties with the jenkins name and email and the email matches what is at the end of the public key.

When Jenkins tries to pull from the git repository (hosted at Github) I get the following:

Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/Test Deployment/workspace
Checkout:workspace / /var/lib/jenkins/jobs/Test Deployment/workspace - hudson.remoting.LocalChannel@9ba3afe
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
ERROR: Error cloning remote repo 'origin' : Could not clone git@github.com:GenRocket/GenRocket.git
hudson.plugins.git.GitException: Could not clone git@github.com:GenRocket/GenRocket.git
    at hudson.plugins.git.GitAPI.clone(GitAPI.java:245)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1121)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1063)
    at hudson.FilePath.act(FilePath.java:839)
    at hudson.FilePath.act(FilePath.java:821)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1063)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1218)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:586)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:475)
    at hudson.model.Run.run(Run.java:1438)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:239)
Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin git@github.com:GenRocket/GenRocket.git /var/lib/jenkins/jobs/Test Deployment/workspace" returned status code 128:
stdout: Cloning into /var/lib/jenkins/jobs/Test Deployment/workspace...

stderr: Host key verification failed.
fatal: The remote end hung up unexpectedly

Not sure what the issue is or what I've forgotten to do with regards to configuration. Any help is appreciated. Let me know if you need more details.

解决方案

Try adding github to the .ssh/known_hosts file of the jenkins user. If you manually try to clone as the jenkins user, it should prompt you to add github.com as a known host. Once you do that, jenkins should be able to verify the host key when doing builds.

这篇关于Jenkins使用Git部署密钥构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆