Jenkins:尝试使用 SSH 拉取存储库时会出现 Git 插件超时



我尝试使用 SSH 将 Jenkins 设置为 GITHUB 到 PULL 存储库。这是我到目前为止所做的

1> 在 Windows 2012 r2 服务器上安装 Jenkins、GitHub 和 Git 插件,并在登录用户帐户下运行 Jenkins 服务。(不是本地系统帐户)

2>按照 GitHub 上的说明创建了 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)JenkinsjobsDEVworkspace
   Cloning the remote Git repository
   Cloning repository git@github.com:mycompanyname/myrepo.git
    > git.exe init C:Program Files (x86)JenkinsjobsDEVworkspace # 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/*

增加克隆和签出的超时

  1. 转到作业配置并找到 git 部分
  2. 添加 ->高级克隆行为。在那里您可以指定超时并检查"浅拷贝"(速度更快)
  3. 添加 -> 高级结账行为。您可以设置结帐超时。

最新更新