0
votes

I have tried hard to setup Jenkins Jobs to connect to bitbucket. It is a windows machine.

  1. I have generated a SSH key pair and added an SSH Key to my Bitbucket.
  2. I have loaded the private key like this using Git-bash

$ ssh-add -l 2048 SHA256:iB//Q8zoeAtGBRrPDnK9yicrANAJs80Fx9tNZSRgHOY /d/jenkins/jenkins_bitbucket (RSA)

After that this command ran without showing an error.

$ git.exe fetch --tags --progress [email protected]:ilppoc/security.git +refs/heads/:refs/remotes/origin/

The result of this command is also fine.

ssh -vT [email protected]

logged in as ilppoc.

You can use git or hg to connect to Bitbucket. Shell access is disabled. debug1: client_input_channel_req: channel 0 rtype exit-status reply 0 debug1: channel 0: free: client-session, nchannels 1 Transferred: sent 3112, received 1728 bytes, in 0.5 seconds Bytes per second: sent 5867.3, received 3257.9 debug1: Exit status 0

But my Windows prompt isn't recognizing the key.

C:\Windows\system32>git ls-remote -h [email protected]:ilppoc/security.git Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

So I converted the OpenSSH private key to Putty .ppk and loaded it manually using pageant. I can see it in the pageant window.

It still doesn't help. As a consequence my Jenkins job fails because as I mentioned this command doesn't run from the windows prompt.

D:\testbitbucketclone\security>git.exe fetch --tags --progress [email protected] :ilppoc/security.git +refs/heads/:refs/remotes/origin/ Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

What is wrong here ?

Additionally known_hosts is filled up. Git-bash works and Windows prompt doesn't ?

How should I fix this ?

Edit : The exact error in Jenkins is this.

Caused by: hudson.plugins.git.GitException: Command "git.exe fetch --tags --progress [email protected]:ilppoc/security.git +refs/heads/:refs/remotes/origin/" returned status code 128: stdout: stderr: Host key verification failed. fatal: Could not read from remote repository.

1

1 Answers

0
votes

If you're running a newer version of git for Windows, you might get useful diagnostic information from the commands (from the Windows command prompt):

set GIT_SSH_COMMAND=ssh -vvv
git clone [email protected]:ilppoc/security.git

That will provide detailed debugging information about ssh as used by git.

If you prefer to run that from the Windows "Git Bash" shell, then the command is:

GIT_SSH_COMMAND="ssh -vvv" git clone [email protected]:ilppoc/security.git