【问题标题】:Jenkins pulling source code from GitHub private repoJenkins 从 GitHub 私有仓库拉取源代码
【发布时间】:2012-08-13 12:58:45
【问题描述】:

我正在尝试在我的服务器中为我的项目设置 Jenkins。

我在 GitHub 私有仓库中上传了我的构建脚本。我已经建立了一个 SSH 密钥,并通过 GitHub 部署它。

但是当我尝试构建时,Jenkins 无法从我的私人仓库中成功提取

这是控制台输出:

Started by user anonymous
Building in workspace /Users/Shared/Jenkins/Home/jobs/moai-test/workspace
Checkout:workspace / /Users/Shared/Jenkins/Home/jobs/moai-test/workspace - hudson.remoting.LocalChannel@15e6e48b
Using strategy: Default
Fetching changes from 1 remote Git repository
Fetching upstream changes from https://github.com/****/****.git
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
hudson.plugins.git.GitException: Error performing command: git fetch -t https://github.com/****/****.git +refs/heads/*:refs/remotes/origin/*
    at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:862)
    at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:817)
    at hudson.plugins.git.GitAPI.fetch(GitAPI.java:197)
    at hudson.plugins.git.GitAPI.fetch(GitAPI.java:1063)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:812)
    at hudson.plugins.git.GitSCM.access$100(GitSCM.java:90)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1096)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1064)
    at hudson.FilePath.act(FilePath.java:842)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1064)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1256)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:589)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:494)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)
Caused by: java.lang.InterruptedException
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:485)
    at java.lang.UNIXProcess.waitFor(UNIXProcess.java:115)
    at hudson.Proc$LocalProc.join(Proc.java:319)
    at hudson.Launcher$ProcStarter.join(Launcher.java:345)
    at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:843)
    ... 18 more
ERROR: Could not fetch from any repository
FATAL: Could not fetch from any repository
hudson.plugins.git.GitException: Could not fetch from any repository
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1103)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1064)
    at hudson.FilePath.act(FilePath.java:842)
    at hudson.FilePath.act(FilePath.java:824)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1064)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1256)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:589)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:494)
    at hudson.model.Run.execute(Run.java:1502)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:236)

【问题讨论】:

  • 你确定Jenkins进程在~user/.ssh目录中实际拥有ssh公钥和私钥的用户下运行吗?
  • 我很确定 Jenkins 正在以拥有私钥的用户身份运行。我已更改 jenkins 配置文件以使用具有 ssh 公钥的用户运行 jenkins。
  • 好的,在这里检查一下。另一个检查:远程 GitHub 地址是否正确(我的意思是,那里没有错字?stackoverflow.com/questions/11485775/…stackoverflow.com/questions/8904327/case-sensitivity-in-git/…
  • 是的,我刚刚用 **** 替换了 GitHub 地址,我使用了正确的地址。
  • 好的(因为一个简单的小写字母而不是大写字母就足以使所有查询失败)

标签: github continuous-integration jenkins


【解决方案1】:

查看您的构建日志

Using strategy: Default
Fetching changes from 1 remote Git repository
Fetching upstream changes from https://github.com/****/****.git
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway

您正在为 github 存储库使用 HTTPS URI。

HTTPS URI 使用用户名/密码而不是 SSH 密钥进行身份验证。

要使用 SSH 密钥,您需要检查 SSH URI,例如

git@github.com:****/****.git

这应该可以解决您的问题。

或者你可以给 Jenkins 用户名/密码(虽然这是一个更大的安全风险)

【讨论】:

  • 我已将 HTTPS URI 更改为 SSH URI,但遇到了另一个问题。控制台输出显示主机密钥验证失败。我确定我已经生成了 id_rsa 密钥,然后将其部署在 github 中。有什么办法可以解决这个问题吗?
  • 要解决此问题,您需要执行 ssh github.com,然后在提示时回答“是”以将 GitHub 添加到受信任主机列表中。您只需在任何给定的机器上执行一次,它将被永久添加。
  • 您需要确保 jenkins 使用的密钥具有空密码。如果我没记错的话,Jenkins 无法处理带有密码短语的键(由于将密码短语提供给程序的复杂性——它试图确保只使用真正的键盘来输入密码短语!)
  • @Stephen Connolly:您应该能够通过 ssh 代理进行预授权来使用密码保护密钥。不过这很复杂,您需要在每次重新启动(或类似情况)时重新进行身份验证
  • @umlaeute,是的,理论上你应该能够做到这一点,但是一些插件使用 java 客户端,而另一些使用 cli 客户端,所以最终结果是一些插件会拿起代理,而另一些插件会炸弹出去。最好最坏的选择是专门为 Jenkins 生成一个密钥,并确保该密钥没有密码。
猜你喜欢
  • 2012-10-19
  • 1970-01-01
  • 2018-06-16
  • 1970-01-01
  • 2019-02-07
  • 1970-01-01
  • 2015-09-19
  • 2022-06-28
  • 1970-01-01
相关资源
最近更新 更多