Search code examples
gitjenkinsbitbucketpermission-deniedpublic-key

error 128 when trying to clone a git repository using jenkins


I can clone my git repository on the Linux server that hosts the Jenkins app, but when I'm trying to create a new Jenkins job to do so, I'm getting error 128.

"Failed to connect to repository : Command "git ls-remote -h ssh://git@bitbucket.org/user/proj.git HEAD" returned status code 128: stdout: stderr: Permission denied (publickey). fatal: Could not read from remote repository.

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

Things I did

  1. Install git on the Linux server.

  2. Install BitBucket plugin and it's dependencies on the Jenkins app.

  3. Create an SSH key.

  4. Import the key to BitBucket and to Jenkins folder.
  5. Set permissions to Jenkins user on the SSH key.
  6. I created SSH credentials on Jenkins app.

WORKS ON TERMINAL

bash-4.2$ bash-4.2$ whoami jenkins bash-4.2$ ssh -T git@bitbucket.org authenticated via a deploy key. You can use git or hg to connect to Bitbucket. Shell access is disabled. This deploy key has read access to the following repositories: user/proj: test3 -- jenkins@git . .

git -c core.askpass=true ls-remote -h ssh://git@bitbucket.org/user/proj.git [ec2-user@ip-172-31-31-13 ~]$ git -c core.askpass=true ls-remote -h ssh://git@bitbucket.org/user/proj.git db710fbf01f08789cf5c15e66269013f8e1543d4 refs/heads/master

IMAGES:

1-linux jenkins ver

2-ssh 2 git using default user

3-ssh 2 git using jenkins user

4-ssh rsa keys

5-jenkins auth keys

6-jenkins cred

7-jenkins web error


Solution

  • I would try to write the URL of the git repository, when configuring it in Jenkins, as git@[...] instead of ssh://git@[...]

    On the other hand, the key you have introduced as private key of test3 (ssh-rsa AAA[...]) doesn't seem to be a private key. It looks like the public key instead. The private key is a block that starts with -----BEGIN RSA PRIVATE KEY----- and ends with -----END RSA PRIVATE KEY-----. In your case I think it's stored in the file named jenkins_bitbucket_access (the public key is stored in jenkins_bitbucket_access.pub)