简体   繁体   中英

Cloning GIT repository by ANT

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 .

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.

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.

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM