通过ANT克隆GIT存储库

时间:2013-07-16 09:33:26

标签: git ant github

我正在使用ANT帮助GIT克隆。我正在使用以下代码:

<target name ="deploy">

 <sshexec host="ssh://user@rep_location/project_name.git"
    username="username"
    password=""
    passphrase="passphrase"
    trust="true"
    command="git clone ssh://user@rep_location/project_name.git  D:/dest"/
    />

</target>

位置“D:/dest”是我希望克隆存储库所需的文件夹。但它会导致unknown host exception错误。

我尝试与ssh://user@rep_location之类的主机进行少量组合,但它也会返回服务器连接超时 我们要求在结账时提供密码。 此命令适用于GIT BASH

3 个答案:

答案 0 :(得分:0)

这应与此“未知主机密钥”经典ssh错误相关联:请参阅“com.jcraft.jsch.JSchException: UnknownHostKey”。

最简单的解决方案仍然是首先手动执行ssh:

  

尝试从命令行ssh并接受公钥(主机将添加到~/.ssh/known_hosts

确保在Windows上定义了HOME个环境变量,JSch used by the sshexec ant task将能够找到%HOME%\.ssh\known_hosts个文件。
这与unix-like git bash会话不同,其中$ HOME始终定义。

答案 1 :(得分:0)

以下错误表示ANT无法解析主机名:

  

未知主机异常

您正在提供git URL作为host参数的值:

 <sshexec host="hostwhereIwanttoclonerepository.com"
    username="username"
    passphrase="passphrase"
    trust="true"
    command="git clone ssh://user@rep_location/project_name.git  D:/dest"/
    />

请记住,您在远程计算机上运行git命令,“username”帐户将需要有效的SSH凭据才能访问git存储库主机。

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

您可能还需要包含jsch jar才能访问SSH Git URL。

答案 2 :(得分: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:目标文件夹