3

I am working over GIT cloning with help on ANT.I am using the below code for it :

<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. But it throws error as unknown host exception.

I tried few combination with host like ssh://user@rep_location but it also returns server connection timeout.
We require a passphrase to be provided at the time of checkout. This command works fine with GIT BASH.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Narendra Pandey
  • 514
  • 4
  • 11
  • 26

3 Answers3

0

This should be linked to this "Unknown Host key" classic ssh error: see "com.jcraft.jsch.JSchException: UnknownHostKey".

The simplest solution remains to do the ssh manually first:

Try to ssh from the command line and accept the public key (the host will be added to ~/.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.
That differs from a unix-like git bash session, where $HOME is always defined.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hello VonC,I rectified my code a little.The host was not right.This time i simply passed "repositry location" in place of "ssh://user@rep_location/project_name.git".By doing so, it is able to connect to repository...but still throwing this error "SSH_MSG_DISCONNECT: 2 Too many authentication failures for username". I am passing the correct credentials.Still the error exist. – Narendra Pandey Jul 17 '13 at 10:03
  • @Narendra and what does `ssh -Tvvv user@rep_location` returns? – VonC Jul 17 '13 at 10:15
  • It asked for passphrase to enter.I did but it shows authentication failure.It sent a password packet to git repository but it returned "Permission denied,Please try again" .And after three attempts it failed. – Narendra Pandey Jul 17 '13 at 10:33
  • i am sure i am passing right credentials as i am able to do it by GIT BASH. – Narendra Pandey Jul 17 '13 at 10:34
  • I have specified GIT_HOME variable in my environment variables and provided its installation folder and later have added it to path variable.I am not sure, what to pass as the address in HOME variable as address,what you suggested me in your first comment – Narendra Pandey Jul 17 '13 at 10:49
  • @Narendra tes, you need to make sure HOME is set and known by ant, otherwise no ssh operation will work from ant. – VonC Jul 17 '13 at 11:25
  • I believe the HOME variable is set right as i have run command echo %HOME% and it returned ".\ssh\known_hosts" as result.But the same error exists of "SSH_MSG_DISCONNECT:2 Too many authentication failures for username".I did search about this error and it looks like i need to set a parameter "IdentitiesOnly" in my /.ssh/config file...which surely is not present in ssh folder. – Narendra Pandey Jul 18 '13 at 06:08
  • @Narendra yes, but is it still visible in the ant command? Plus `echo %HOME%` shoudl return the **parent directory** of `.ssh\known_hosts`. It should *not* return `.ssh\known_hosts` itself. – VonC Jul 18 '13 at 06:10
0

The following error means ANT cannot resolve the hostname:

unknown host exception

You are supplying a git URL as the value of the host parameter:

 <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.

Finally, I suspect you're trying to clone the repository locally? In that case you should not be using the sshexec task. I recommend trying the "git-clone" ANT task from jGit. For an example:

You may need to also include the jsch jar in order to access an SSH Git URL.

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Hello mark,i read your post.I need to pass passphrase while checking out from git repository.I don't get the proper field to pass it.Simly running the code returns "USERAUTH fail" exception. – Narendra Pandey Jul 17 '13 at 10:01
0
<exec executable="${gitBinPath}">
    <arg value="clone" />
    <arg value="--depth" />
    <arg value="1" /> 
    <arg value="${gitRepositoryURL}" />
    <arg value="${deployDir}" />
</exec>
  • gitBinPath: Location to git.exe
  • gitRepositoryURL: Git Repository URL
  • deployDir: Destination folder

Sid
  • 693
  • 6
  • 8