簡體   English   中英

通過ANT克隆GIT存儲庫

[英]Cloning GIT repository by ANT

我正在使用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一起使用效果很好。

這應該鏈接到此“未知主機密鑰”經典ssh錯誤:請參閱“ com.jcraft.jsch.JSchException:UnknownHostKey ”。

最簡單的解決方案仍然是先手動執行ssh:

嘗試從命令行ssh並接受公鑰(主機將添加到~/.ssh/known_hosts

確保在Windows上定義了HOME環境變量, sshexec ant任務所使用JSch在其中可以找到%HOME%\\.ssh\\known_hosts文件。
這與像unix一樣的git bash會話不同,后者始終定義$ HOME。

以下錯誤表示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命令,“用戶名”帳戶將需要有效的SSH憑據才能訪問git存儲庫主機。

最后,我懷疑您正在嘗試在本地克隆存儲庫? 在這種情況下,您不應使用sshexec任務。 我建議嘗試從jGit執行“ git-clone” ANT任務。 例如:

您可能還需要包括jsch jar才能訪問SSH Git URL。

<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:目標文件夾

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM