使用Git和部署密钥构建Jenkins

Gre*_*egg 5 git github jenkins

我将git插件添加到Jenkins.我在构建服务器上生成了一个公钥作为jenkins用户.我将此密钥添加为github的Deploy Key.我已经使用jenkins名称和电子邮件添加了全局git属性,并且电子邮件与公钥末尾的内容匹配.

当Jenkins试图从git存储库(在Github上托管)中提取时,我得到以下内容:

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
Run Code Online (Sandbox Code Playgroud)

不确定问题是什么或我忘记了配置方面的问题.任何帮助表示赞赏.如果您需要更多详细信息,请告诉我们.

jbo*_*les 6

对于权限被拒绝错误,您需要确保使用已创建的密钥.为此,在〜/ .ssh目录中创建一个名为"config"的文件.使用以下内容填充配置文件:

  • HostName github.com
  • 用户git
  • IdentityFile~/.ssh/id_rsa
  • 身份只是的

只需确保IdentityFile值指向您的密钥.:)

请使用以下内容进行验证:ssh -vT git@github.com


kjw*_*188 4

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