git fetch with refspec参数导致空响应

时间:2015-06-21 13:17:02

标签: git jenkins

我在使用jenkins的git插件时遇到问题。

詹金斯:1.617
git:1.9.5.msysgit.1
操作系统:Windows Server 2012

jenkins作业的控制台输出是:

Building in workspace C:\Program Files (x86)\Jenkins\jobs\Test\workspace
 > git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git.exe config remote.origin.url ssh://git@localhost:22/projects/DW.git # timeout=10
Fetching upstream changes from ssh://git@localhost:22/projects/DW.git
 > git.exe --version # timeout=10
using GIT_SSH to set credentials 
 > git.exe -c core.askpass=true fetch --tags --progress ssh://git@localhost:22/projects/DW.git +refs/heads/*:refs/remotes/origin/*
ERROR: Timeout after 10 minutes
ERROR: Error fetching remote repo 'origin'

基于Jenkins控制台输出,我检查了windows控制台中git.exe的行为:

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>git.exe -c core.askpass=true
fetch --tags --progress ssh://git@localhost:22/projects/DW.git +re
fs/heads/*:refs/remotes/origin/*
Enter passphrase for key '/.ssh/id_rsa':

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>

但是当终端在没有refspec参数(git fetch [<options>] [<repository> [<refspec>…]])的情况下执行命令时,git会按预期响应:

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>git.exe -c core.askpass=true
fetch --tags --progress ssh://git@localhost:22/projects/DW.git
Enter passphrase for key '/.ssh/id_rsa':
From ssh://localhost:22/projects/DW
 * branch            HEAD       -> FETCH_HEAD

为了检查另一个存储库的响应方式,我使用了GitHub存储库:

C:\gittest>git.exe -c core.askpass=true fetch --tags --progress https://github.
om/skeeto/sample-java-project.git +refs/heads/*:refs/remotes/origin/*
remote: Counting objects: 423, done.
rReceiving oemote: Total 423 (delta 0), reused 0 (delta 0), pabjects:  77% (326
Receiving obj
Receiving objects: 100% (423/423), 64.84 KiB | 0 bytes/s, done.
Resolving deltas: 100% (162/162), done.
From https://github.com/skeeto/sample-java-project
 * [new branch]      lwjgl      -> origin/lwjgl
 * [new branch]      lwjgl-cube -> origin/lwjgl-cube
 * [new branch]      lwjgl-lib  -> origin/lwjgl-lib
 * [new branch]      master     -> origin/master
 * [new branch]      minimal    -> origin/minimal
 * [new branch]      noise      -> origin/noise
 * [new branch]      servlet    -> origin/servlet

此外,我使用以下命令检查了远程目录:

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>git remote
origin

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>git remote -v
origin  ssh://git@localhost:22/projects/DW.git (fetch)
origin  ssh://git@localhost:22/projects/DW.git (push)

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>git branch -r
  origin/master

C:\Program Files (x86)\Jenkins\jobs\Test\workspace>git ls-remote
Enter passphrase for key '/.ssh/id_rsa':
From ssh://git@localhost:22/projects/DW.git
a41ca12aa99d2764ff397e7b452ac1e6b2607735        HEAD
a41ca12aa99d2764ff397e7b452ac1e6b2607735        refs/heads/master

1 个答案:

答案 0 :(得分:1)

我找到了解决方案:

似乎是jenkins中的一个错误已经在unix / linux环境中修复但在windows中没有修复: https://issues.jenkins-ci.org/browse/JENKINS-20879

我从id_rsa密钥文件中删除了密码(在右侧/.ssh/目录中)

$ ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile]