4

I want to put one of my jenkins projects into source code management with git.

However, when I typed git@gitlab.com:myGitlabAccount/myProjectName.git into Repository URL under Source Code Management tab in the project configuration page. I saw the following error message:

Failed to connect to repository : Command "git.exe ls-remote -h git@gitlab.com:myGitlabAccount/myProjectName.git" returned status code 128:
stdout: 
stderr: Host key verification failed. 
fatal: Could not read from remote repository.

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

There's no error message when I type git.exe ls-remote -h git@gitlab.com:myGitlabAccount/myProjectName.git under windows command line.

I can git clone git@gitlab.com:myGitlabAccount/myProjectName.git successfully.

And I think that Jenkins Host key verification failed is a solution to my problem if I were a linux jenkins user.

But I use jenkins under windows environment, and I don't find any user called jenkins in windows.

How can I switch to jenkins user and type git ls-remote -h git@bitbucket.org:person/projectmarket.git HEAD manually in windows environment?

Community
  • 1
  • 1
Brian
  • 12,145
  • 20
  • 90
  • 153

4 Answers4

9

If you installed Jenkins per default as a Windows service, you can copy a file named "known_hosts" under the directory

C:\Windows\System32\Config\SystemProfile\ .ssh

This will be read by Jenkins then and allow it to access your Git server.

5

enter image description here

Because I installed jenkins as a windows service, I have to go to jenkins service page, and change its login account to the account I use to login windows.

In this way, jenkins can access the known_hosts file I used in my windows environment.

Jonathan Sudiaman
  • 3,364
  • 1
  • 13
  • 15
Brian
  • 12,145
  • 20
  • 90
  • 153
4

You need to generate ssh keys on your jenkins machine and add them to your gitlab account

If you are using windows open git bash and type the following:

# generate keys
ssh-keygen -t rsa

click ENTER on each step and if you already have a key you will get a warning that a certificate already exist.

Now copy the public key and paste it under you gitlab account

# grab the key
cat ~/.ssh/id_rsa.pub

Login you your gitlab account and add this key (you will see ssh-keys on the top menu once logged in)

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • I already generated the key-pair and pasted the public key to my gitlab account. I can `git clone git@gitlab.com:myGitlabAccount/myProjectName.git` without any problem. – Brian Jan 21 '17 at 14:01
  • Now open gitbash and type `git fetch` you should see a question on the screen asking you to add the key to the know hosts. type yes and try to clone form jenkins – CodeWizard Jan 21 '17 at 14:02
  • No, I don't see any response after typing `git fetch` under my local repository. – Brian Jan 21 '17 at 14:04
  • If you did not get any error its good, do the same on the jenkins machine/ account – CodeWizard Jan 21 '17 at 14:13
1

One alternative which worked for me is to use HTTPS rather then SSH link under "Clone or Download tab". With SSH I am still seeing issue which i have to analyze more, but for time being HTTPS worked straight forward.

Zoe
  • 27,060
  • 21
  • 118
  • 148