# Git clone fail on jenkins

**URL:** <https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [September 8, 2022, 7:16am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680 "2022-09-08T07:16:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://community.jenkins.io/u/eagle)\
**Post date:** [September 8, 2022, 7:16am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/1 "2022-09-08T07:16:47Z")

</div>

Hello  
I attemp to clone the source code from git server through Jenkins and here is my steps.  
OS: window 10  
Jenkins: 2.365

1. I program the git clone with python and verfy it can work normally.

import git  
from git import Git  
from git import Repo  
git\_ssh\_cmd = ‘ssh -i C:/Users/ewu19/.ssh/id\_rsa’  
Repo.clone\_from(“git\_server:UEFI/Platform/amd\_genoa/uefi\_genoa\_tp\_platform.git”,  
“C:/mytest/test”,  
env={“GIT\_SSH\_COMMAND”: git\_ssh\_cmd})

1. Launch the python in Jenkins build-in windows batch then build now  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/0/019974a7ad68f8069a34fdf0aa1d3ade6ab1464c.png)

3 . the error outputs to console as below  
Traceback (most recent call last):  
File “C:\_Doc\Python\Git\_Clone.py”, line 6, in Repo.clone\_from(“git\_server”:UEFI/Platform/amd\_genoa/uefi\_genoa\_tp\_platform.git",  
File “C:\Users\ewu19\AppData\Local\Programs\Python\Python310\lib\site-packages\git\repo\base.py”, line 1148, in clone\_from  
return cls.\_clone(git, url, to\_path, GitCmdObjectDB, progress, multi\_options, \*\*kwargs)  
File “C:\Users\ewu19\AppData\Local\Programs\Python\Python310\lib\site-packages\git\repo\base.py”, line 1086, in \_clone  
finalize\_process(proc, stderr=stderr)  
File “C:\Users\ewu19\AppData\Local\Programs\Python\Python310\lib\site-packages\git\util.py”, line 386, in finalize\_process  
proc.wait(\*\*kwargs)  
File “C:\Users\ewu19\AppData\Local\Programs\Python\Python310\lib\site-packages\git\cmd.py”, line 502, in wait  
raise GitCommandError(remove\_password\_if\_present(self.args), status, errstr)  
git.exc.GitCommandError: Cmd(‘git’) failed due to: exit code(128)  
cmdline: git clone -v git\_server:UEFI/Platform/amd\_genoa/uefi\_genoa\_tp\_platform.git C:/mytest/test  
stderr: 'Cloning into ‘C:/mytest/test’…  
Host key verification failed.  
fatal: Could not read from remote repository.

Please make sure you have the correct access rights  
and the repository exists.

have any ideas for the problem, thanks for your help

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [September 8, 2022, 12:53pm UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/2 "2022-09-08T12:53:47Z")

</div>

Why are you cloning this way? It seems overkill instead of just using the cloning functionality in Jenkins itself.

You are settings env to something, but never using it before the clone command, so how will git be able to use the env? You are getting an error right in the output, so I would start there.

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [September 8, 2022, 1:38pm UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/3 "2022-09-08T13:38:49Z")

</div>

> [@eagle](#):
>
> Host key verification failed.  
> fatal: Could not read from remote repository

As @slide_o_mix said, that message is probably the key to what you need to change if you intend to perform the `git clone` from inside your Python script. You’re attempting to clone using the `ssh` protocol but the host key of the remote server is not known on the agent that is performing the `git` command.

The `~/.ssh/known_hosts` file is the usual location where host keys are written for ssh based clone of repositories. On Windows, that would be in `%HOMEDRIVE%%HOMEPATH%\.ssh\known_hosts` .

---

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://community.jenkins.io/u/eagle)\
**Post date:** [September 15, 2022, 1:57am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/4 "2022-09-15T01:57:22Z")

</div>

Mark  
your ideas is that I should include the know\_hosts file in my python isn,t it?

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [September 15, 2022, 4:13pm UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/5 "2022-09-15T16:13:05Z")

</div>

> [@eagle](#):
>
> your ideas is that I should include the know\_hosts file in my python isn,t it?

Yes, since you’ve decided to take responsibility for the `git clone` in your Python script, I think you should also take responsibility for the configuration that will allow you to run the `git clone`.

---

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://community.jenkins.io/u/eagle)\
**Post date:** [September 16, 2022, 3:30am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/6 "2022-09-16T03:30:36Z")

</div>

@MarkEWaite  
thanks,  
one question , as I know if i attemp to clone from git, the id\_rsa key pair(private/public) are necessary,  
the known\_host is recorded the git server’s pubkey in client on the first connecting to git server through .ssh, so is the known\_host necessay or any method can ignore it?

---

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://community.jenkins.io/u/eagle)\
**Post date:** [September 16, 2022, 3:41am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/7 "2022-09-16T03:41:52Z")

</div>

I did clone from git server with Build-in clone of Jenkins, it can work normally clone my source code in the worksapce

 ![1](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/5/5f9b99e39f2ecbb5c48ea6ffc826f84e8f111120.png)  
But I still want to figure out why I can not use gitpython to clone dirrectly, lol just for analyze due to I am a rookie in Jenkins

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [September 16, 2022, 3:45am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/8 "2022-09-16T03:45:36Z")

</div>

> [@eagle](#):
>
> git server’s pubkey in client on the first connecting to git server through .ssh, so is the known\_host necessay or any method can ignore it?

If you’re taking responsibility for the `git clone` by calling command line git and by creating the correct private key file, I think you should also assure that the correct host key is in the `known_hosts` file.

Yes, sometimes the python program may run in an environment that has already configured a `known_hosts` file, but I would not want to depend on that.

Ephemeral agents may not be a thing you’re using now, but there will likely come a time in the future when you’ll want to run from an agent that exists only for the duration of the single job.

---

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://community.jenkins.io/u/eagle)\
**Post date:** [September 16, 2022, 5:35am UTC](https://community.jenkins.io/t/git-clone-fail-on-jenkins/3680/9 "2022-09-16T05:35:29Z")

</div>

Thanks for your answer, I understood and will keep to study and find the solution out  
thumbs up!
