2
votes

I have a setup of 2 VMs : VM1 with jenkins, VM2 with gitlab

On VM2 I have created a repo with user root with public access http://192.168.0.32/root/sparkjava_hello_world (acccess OK) and generate the access token

On VM1: - I installed the gitlab plugin in jenkins - I copied the public key of user jenkins to authorized_key of user git in VM2 : from user jenkins shell, ssh git@VM2 is OK, no password asked - I created the gitlab api credential and pasted the access token in it - I configured the gitlab url in Manage Jenkins -> Configure System menu (it responds ok)

BUT when I setup the git source [email protected]:root/sparkjava_hello_world.git in my jenkins job, it doesnt work :

Failed to connect to repository : Command "/usr/bin/git ls-remote -h [email protected]:root/sparkjava_hello_world.git HEAD" returned status code 128: stdout: stderr: fatal: 'root/sparkjava_hello_world.git' does not appear to be a git repository fatal: Could not read from remote repository.

I assume the ssh connection to VM2 is ok, since this is not a connection refused message.

I tried "ssh://[email protected]:root/sparkjava_hello_world.git" doesnt work either

What did i missed, or did wrong ?? thanks for help :)

1
Your error message says "Failed to connect to repository" so it appears to me that the connection was refused. You might try SSHing into the jenkins VM and trying to manually clone the repo.Loren

1 Answers

1
votes

Check that in VM2 you do have (as defined by default in a typical gitlab.yml) a /home/git/repositories/root/sparkjava_hello_world.git

Try an interactive ssh session on VM2 (from VM1), and do the ls-remote there:

ssh [email protected]
git ls-remote /home/git/repositories/root/sparkjava_hello_world.git

For Jenkins, what you need is to use your public key (~/.ssh/id_rsa.pub) as:

Make sure to deploy that deploy key on your GitLab project (project settings/deploy keys), and then your Jenkins will be able to access your GitLab project (using that ssh key as credential).


Note: the normal use of a GitLab user key (like user xxx) in VM1 would be:

  • to define a user xxx in GitLab
  • to associate its public key in its user settings/ssh keys (that will modify ~git/.ssh/authorized_keys for you, adding a forced command line (this link is for gitolite, but it applies to gitlab too)

That means an ssh -T [email protected] should not open an interactive session, but generate the message:

Welcome to GitLab, xxx