github - Jenkins 从 GitHub 私有(private)仓库拉取源代码

标签 github continuous-integration jenkins

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

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

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

这是控制台输出:

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)

最佳答案

查看您的构建日志

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 key 进行身份验证。

要使用 SSH key ,您需要检查 SSH URI,例如
git@github.com:****/****.git

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

或者,您可以为 Jenkins 提供用户名/密码(尽管这是一个更大的安全风险)

关于github - Jenkins 从 GitHub 私有(private)仓库拉取源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11999670/

相关文章:

docker - 如何安全地从 GitLab Runner KubernetesExecutor pod 推送到私有(private)容器注册表?

c++ - 使用 bitbakes 在 openEmbedded 环境下部署 Jenkins

git - Jenkins:从另一个存储库而不是我要构建的存储库加载 Jenkinsfile

java - 如何使用 Jenkins CI 部署 Java EE 应用程序?

java - 在 Jenkins 中使用 Maven 解析 POM 文件时出错

git - 无法使用 Powershell 推送到 github

git - 错误 merge 后恢复未提交的更改

git - 当两个人提交到 GitHub 存储库时会发生什么?

Maven 发布插件 : Permission denied (publickey) Github

Jenkins 管道作业构建