[英]Cloning GIT repository by ANT
I am working over GIT cloning with help on ANT.I am using the below code for it : 我正在使用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>
The location " D:/dest
" is the required folder where I want my repository cloned. 位置“ D:/dest
”是我要将存储库克隆到的必需文件夹。 But it throws error as unknown host exception
. 但是它将错误作为unknown host exception
。
I tried few combination with host like ssh://user@rep_location
but it also returns server connection timeout. 我尝试过与ssh://user@rep_location
类的主机进行一些组合,但它还会返回服务器连接超时。
We require a passphrase to be provided at the time of checkout. 我们要求在结帐时提供密码。 This command works fine with GIT BASH
. 该命令与GIT BASH
一起使用效果很好。
This should be linked to this "Unknown Host key" classic ssh error: see " com.jcraft.jsch.JSchException: UnknownHostKey ". 这应该链接到此“未知主机密钥”经典ssh错误:请参阅“ com.jcraft.jsch.JSchException:UnknownHostKey ”。
The simplest solution remains to do the ssh manually first: 最简单的解决方案仍然是先手动执行ssh:
Try to ssh from the command line and accept the public key (the host will be added to
~/.ssh/known_hosts
) 尝试从命令行ssh并接受公钥(主机将添加到~/.ssh/known_hosts
)
Make sure, on Windows, that you have a HOME
environment variable defined, in which the JSch used by the sshexec ant task will be able to find %HOME%\\.ssh\\known_hosts
file. 确保在Windows上定义了HOME
环境变量, sshexec ant任务所使用的JSch在其中可以找到%HOME%\\.ssh\\known_hosts
文件。
That differs from a unix-like git bash session, where $HOME is always defined. 这与像unix一样的git bash会话不同,后者始终定义$ HOME。
The following error means ANT cannot resolve the hostname: 以下错误表示ANT无法解析主机名:
unknown host exception 未知主机异常
You are supplying a git URL as the value of the host parameter: 您正在提供一个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"/
/>
Keep in mind that you are running the git command on a remote machine, the "username" account will require valid SSH credentials to access the git repository host. 请记住,您正在远程计算机上运行git命令,“用户名”帐户将需要有效的SSH凭据才能访问git存储库主机。
Finally, I suspect you're trying to clone the repository locally? 最后,我怀疑您正在尝试在本地克隆存储库? In that case you should not be using the sshexec task. 在这种情况下,您不应使用sshexec任务。 I recommend trying the "git-clone" ANT task from jGit . 我建议尝试从jGit执行“ git-clone” ANT任务。 For an example: 例如:
You may need to also include the jsch jar in order to access an SSH Git URL. 您可能还需要包括jsch jar才能访问SSH Git URL。
<exec executable="${gitBinPath}">
<arg value="clone" />
<arg value="--depth" />
<arg value="1" />
<arg value="${gitRepositoryURL}" />
<arg value="${deployDir}" />
</exec>
deployDir: Destination folder deployDir:目标文件夹
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.