11

I can't configure the git repository url in a way, that Jenkins could access it.

under "Project > Configure > Source Code Management" I set the Repository URL to "git@store:repositories/testproject.git"

I get this error:

Failed to connect to repository : Command "/usr/bin/git -c core.askpass=true ls-remote -h git@store:repositories/testproject.git HEAD" returned status code 128:
stdout: 
stderr: Permission denied, please try again. 
Permission denied, please try again. 
Permission denied (publickey,password). 
fatal: Could not read from remote repository.

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

the access with that URL works on a shell:

jenkins@dilbert:~$ /usr/bin/git -c core.askpass=true ls-remote -h git@store:repositories/testproject.git
git@store's password: 
4fd35a4f528e2f2921a52cfd03918b7cbde3d253    refs/heads/master

I am asked for a password and it works.

I associated the same password to credentials in Jenkins to "git/" and I also tried "git@store/". None worked.

Pleas note, that this is not about github, but about a local git repository.

update:

adding the pub key from the jenkins master to the build slave, helped to get the configuration working:

ssh-copy-id jenkins@dilbert

now the builds are failing:

 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url git@store:repositories/testproject.git # timeout=10
Fetching upstream changes from git@store:repositories/testproject.git
 > /usr/bin/git --version # timeout=10
 > /usr/bin/git -c core.askpass=true fetch --tags --progress git@store:repositories/testproject.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git@store:repositories/testproject.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:735)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:983)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1016)
    at hudson.scm.SCM.checkout(SCM.java:484)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1270)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:609)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:531)
    at hudson.model.Run.execute(Run.java:1751)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:89)
    at hudson.model.Executor.run(Executor.java:240)
Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git -c core.askpass=true fetch --tags --progress git@store:repositories/testproject.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
fatal: Could not read from remote repository.

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

store is the jenkins master, dilbert is the build slave. ssh from master to slave works.

jenkins@store:~$ ssh dilbert uptime
 16:06:21 up 3 days, 18:53, 13 users,  load average: 0,31, 0,38, 0,50

any ideas how to debug this?

Jörg Beyer
  • 213
  • 1
  • 2
  • 6

1 Answers1

5

authentication works via ssh. have you added the public ssh-key of the jenkins user to the git-user on your git-server?

let me know if you need instructions on how to set up ssh-authentication and i'll edit this post here.

/EDIT:

glad you got it running. i looked on the official jenkins website for a detailed manual on the ssh part of the configuration, but i couldn't find any.

so here's a quick overview - let me know if this is what you need.

  1. jenkins slave (the building machine) connects to the git-server (jenkins master)
  2. building machine runs as jenkins user (e.g. jenkins@dilbert:~$ )
  3. git-server runs as git user (e.g. git@store:~$ )
  4. jenkins@dilbert public key needs to be placed in git@store authorized_keys
  5. run jenkins@dilbert:~/.ssh$ ssh-copy-id git@store to copy jenkins@dilbert ssh public key to the git server
kindaleek
  • 76
  • 5
  • could you please explain which users ssh-key add to where? – Jörg Beyer Mar 22 '15 at 14:36
  • the jenkins user should have his pub-key stored in /.ssh/id_rsa.pub this one needs to be added to /.ssh/authorized_keys – kindaleek Mar 22 '15 at 14:38
  • doing "jenkins@store:~/.ssh$ ssh-copy-id git@store" get's jenkins to accept the configuration (that is an improvement), but a build on a remote jenkins slave fails. any idea? – Jörg Beyer Mar 22 '15 at 14:49
  • good to read. unfortunately, my experience with git ends pretty much there... but i remember a similar problem at work. i might be mistaken now, but you have to work as a user (e.g. Joerg Beyer) on the git-platform, right? please verify the permission there (you can change the users permissions in the web interface for each group they belong to). try to set it to developer for testing **/EDIT:** you wrote remote jenkins slave - if it uses a different key pair, you need to add the public key to the git's authorized_keys once again – kindaleek Mar 22 '15 at 14:59
  • not sure. I updated the question. What ssh key do I need to add where? – Jörg Beyer Mar 22 '15 at 15:12
  • `Permission denied (publickey,password).` still points to an ssh-issue. i think you need to add the ssh keys the other way around. slave to master, so jenkins@dilbert public key to git@store authorized_keys file `jenkins@dilbert:~/.ssh$ ssh-copy-id git@store` – kindaleek Mar 22 '15 at 15:26
  • now it worked. Is there a setup guide for build slaves in situations like this? that would make your answer perfect. – Jörg Beyer Mar 22 '15 at 15:37
  • Part 2 of your question about `ERROR: Error fetching remote repo 'origin'` is also asked at http://stackoverflow.com/questions/35445619/jenkins-error-fetching-remote-repo-origin – MarkHu Feb 23 '16 at 21:40