我的目标是将私有Github存储库拉到Jenkins .
以下是一些背景:
-
MacOS
-
Jenkins在本地托管,
localhost:8080
-
在Jenkins中安装了Git插件和Github插件 .
-
如果我将存储库转为Public,Jenkins的一切都很好 .
-
从命令行,我可以使用我在Jenkins中使用的相同凭据来执行"git clone"私有仓库 .
但是当我把它变成私人并将它用作詹金斯的来源时,它就被打破了 .
错误是:
Building in workspace /Users/Shared/Jenkins/Home/jobs/TestFramework/workspace
> /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> /usr/bin/git config remote.origin.url https://github.com/XXXXXXX/testframework.git # timeout=10
Fetching upstream changes from https://github.com/XXXXXXX/testframework.git
> /usr/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials
> /usr/bin/git fetch --tags --progress https://github.com/XXXXXXX/testframework.git +refs/heads/*:refs/remotes/origin/* # timeout=5
ERROR: Timeout after 5 minutes
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.com/XXXXXXX/testframework.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:806)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1070)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1101)
at hudson.scm.SCM.checkout(SCM.java:496)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1278)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1728)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:405)
Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress https://github.com/XXXXXXX/testframework.git +refs/heads/*:refs/remotes/origin/*" returned status code 143:
I tried a few suggestions online:
-
ssh-keygen到/Users/shared/jenkins/.ssh/id_rsa
-
ssh-keygen到/Users/jason/.ssh/id_rsa
-
将相应的"id_rsa.pub"添加到私有存储库"Settings" => "Deploy keys" .
但仍然没有工作 .
1 回答
我想问题可能是:当Jenkins尝试克隆回购或获取有关回购的信息时,它将使用名为jenkins的用户名 . 当然,此用户无权访问您的私人仓库 . 如果从命令行执行此操作,您将使用自己的用户名,因此可以成功克隆存储库 .
您可以通过在项目配置中更改源代码管理的设置来解决此问题 .
我们正在做的是为github repo使用“带密码的用户名”凭证 .
输入"Repository URL"后,可以单击"Credential"附近的"Add"按钮添加"Username with password"凭证 .
在弹出窗口中,为"Kind"字段选择"Username with password" .
输入您的Github帐户的用户名和密码并保存 .
然后,您可以在设置源代码管理时选择刚刚在"Credential"字段中添加的此凭据 .
希望这可以帮到你 .
(使用凭证插件添加您的帐户和密码在某种程度上是安全的,因此您无需担心公开您的帐户和密码)