Jenkins:当尝试使用SSH

时间:2016-01-28 18:20:17

标签: git github jenkins ssh

我尝试使用SSH将Jenkins设置为从github获取存储库。这是我到目前为止所做的事情

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

2>根据GitHub上的说明here创建SSH。 (注意我在创建时使用了密码短语)

3>我可以看到私人&公钥是在

下创建的
  

C:\用户{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运行以下命令并输入passphrase,我能够从gitbash中提取存储库。

git.exe -c core.askpass=true fetch --tags --progress git@github.com:mycompanyname/myrepo.git +refs/heads/*:refs/remotes/origin/*

1 个答案:

答案 0 :(得分:4)

增加克隆和结帐的超时时间

  1. 转到工作配置并找到git部分
  2. 添加 - >高级克隆行为。在那里你可以指定超时并检查浅拷贝' (这更快)
  3. 添加 - >高级结账行为。您可以设置退房时间。