2013-07-16 123 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:目標文件夾