【发布时间】:2016-11-18 22:01:33
【问题描述】:
我尝试使用 SSH 将 Jenkins 设置为从 github 提取存储库。这是我到目前为止所做的事情
1> 在 Windows 2012 r2 服务器上安装了 Jenkins、GitHub 和 Git 插件,并在登录的用户帐户下运行 jenkins 服务。 (不是本地系统帐户)
2>按照 GitHub 上的说明 here 创建 SSH。 (注意我在创建时使用了密码)
3>我可以看到私钥和公钥是在
下创建的c:\users{loggedusername}.ssh
3>向 ssh-agent 添加 SSH 密钥,同时向 github 添加公钥
4>在 jenkins 中,使用 SSH 私钥和密码(这是我在创建 SSH 时使用的密码)创建了新的全局凭据
5>在 jenkins 中,配置 github SSH url 并使用上面创建的 SSH 凭据
git@github.com:mycompanyname/myrepo.git
6>点击立即构建
7>在控制台窗口中,我在 10 分钟后看到以下错误,状态码为 -1
Started by user James Smith
Building in workspace C:\Program Files (x86)\Jenkins\jobs\DEV\workspace
Cloning the remote Git repository
Cloning repository git@github.com:mycompanyname/myrepo.git
> git.exe init C:\Program Files (x86)\Jenkins\jobs\DEV\workspace # timeout=10
Fetching upstream changes from git@github.com:mycompanyname/myrepo.git
> git.exe --version # timeout=10
using GIT_SSH to set credentials SSH
> git.exe -c core.askpass=true fetch --tags --progress git@github.com:mycompanyname/myrepo.git +refs/heads/*:refs/remotes/origin/*
ERROR: Timeout after 10 minutes
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git.exe -c core.askpass=true fetch --tags --progress git@github.com:mycompanyname/myrepo.git +refs/heads/*:refs/remotes/origin/*" returned status code -1:
stdout:
stderr: Warning: Permanently added the RSA host key for IP address '192.30.XXX.XXX' to the list of known hosts.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1693)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1441)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:62)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:313)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:505)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1013)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1053)
at hudson.scm.SCM.checkout(SCM.java:485)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1276)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:607)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
at hudson.model.Run.execute(Run.java:1738)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:410)
ERROR: null
Finished: FAILURE
我认为我已正确设置 SSH 凭据,否则在上面的第 5 步中,如果 Jenkins 无法连接到 GitHub,我会收到红色错误
我也可以从 gitbash 运行下面的命令并输入密码,然后我就可以从 gitbash 中提取存储库了。
git.exe -c core.askpass=true fetch --tags --progress git@github.com:mycompanyname/myrepo.git +refs/heads/*:refs/remotes/origin/*
【问题讨论】:
-
我有一个非常大的 git 存储库,以至于我需要更改克隆超时。查看此comment 了解更多信息
-
如果我使用用户名/密码和 https url 那么它的工作..但是 SSH 我得到了上述错误。我认为它无法使用 SSH 连接,但我不知道我错过了什么