2013-07-16 146 views
2

我工作过GIT克隆与ANT.I帮助我使用下面的代码吧:克隆Git仓库通过ANT

<target name ="deploy"> 

<sshexec host="ssh://[email protected]_location/project_name.git" 
    username="username" 
    password="" 
    passphrase="passphrase" 
    trust="true" 
    command="git clone ssh://[email protected]_location/project_name.git D:/dest"/ 
    /> 

</target> 

位置“D:/dest”是所需的文件夹,我想我的仓库克隆。但它报错为unknown host exception

我尝试了一些像主机ssh://[email protected]_location几个组合,但它也返回服务器连接超时。
我们需要在结帐时提供密码。 该命令适用于GIT BASH

回答

0

这应该链接到这个“未知的主机密钥”经典ssh错误:请参阅“com.jcraft.jsch.JSchException: UnknownHostKey”。

最简单的办法仍然是手动首先做的SSH:

Try to ssh from the command line and accept the public key (the host will be added to ~/.ssh/known_hosts)

确保,在Windows上,你必须定义的HOME环境变量,其中JSch used by the sshexec ant task就能找到%HOME%\.ssh\known_hosts文件。
不同于类似unix的git bash会话,其中总是定义$ HOME。

+0

你好VonC,我纠正了一下我的代码。主机是不正确的。这次我只是通过“存储位置”来代替“ssh://[email protected]_location/project_name.git”。通过这样做,它能够连接到存储库...但仍然抛出此错误“SSH_MSG_DISCONNECT:2用户名认证失败太多”。我正在传递正确的凭据,但仍然存在错误。 –

+0

@Narendra和'ssh -Tvvv user @ rep_location'返回什么? – VonC

+0

它要求输入密码。我做了,但是显示认证失败。它向git存储库发送了一个密码包,但它返回了“Permission denied,Please try again”。并且三次尝试失败。 –

0

以下错误意味着ANT无法解析主机名:

unknown host exception

您提供一个git URL作为主机参数的值:

<sshexec host="hostwhereIwanttoclonerepository.com" 
    username="username" 
    passphrase="passphrase" 
    trust="true" 
    command="git clone ssh://[email protected]_location/project_name.git D:/dest"/ 
    /> 

请记住,你正在运行的git命令在远程机器上,“用户名”帐户将需要有效的SSH凭据来访问git存储库主机。

最后,我怀疑你试图克隆本地存储库?在这种情况下,你不应该使用sshexec任务。我建议尝试使用jGit的“git-clone”ANT任务。举一个例子:

您可能还需要包括以访问SSH的Git URL的jsch罐子。

+0

你好马克,我读你的帖子。我需要通过密码,而检查从git repository.I没有得到适当的领域来传递它。只是运行代码返回“USERAUTH失败”例外。 –

0
<exec executable="${gitBinPath}"> 
    <arg value="clone" /> 
    <arg value="--depth" /> 
    <arg value="1" /> 
    <arg value="${gitRepositoryURL}" /> 
    <arg value="${deployDir}" /> 
</exec> 
  • gitBinPath:位置,以git.exe
  • gitRepositoryURL:Git仓库URL
  • deployDir:目标文件夹