Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-33983

Multibranch Pipeline with git uses jgit, but should use git installation that is configured

      When I create Multibranch Pipeline and add a git source (which requires a private key to authenticate) branch indexing doesn't work and throws following exception:

      java.lang.IllegalStateException: Cannot open session, connection is not authenticated.
      	at com.trilead.ssh2.Connection.openSession(Connection.java:1127)
      	at org.jenkinsci.plugins.gitclient.trilead.TrileadSession.exec(TrileadSession.java:32)
      	at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:262)
      	at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:161)
      	at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
      	at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
      	at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1138)
      	at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:130)
      	at org.jenkinsci.plugins.gitclient.JGitAPIImpl.fetch(JGitAPIImpl.java:672)
      	at jenkins.plugins.git.AbstractGitSCMSource.retrieve(AbstractGitSCMSource.java:171)
      	at jenkins.scm.api.SCMSource.fetch(SCMSource.java:146)
      	at jenkins.branch.MultiBranchProject.computeChildren(MultiBranchProject.java:296)
      	at com.cloudbees.hudson.plugins.folder.computed.ComputedFolder.updateChildren(ComputedFolder.java:151)
      	at com.cloudbees.hudson.plugins.folder.computed.FolderComputation.run(FolderComputation.java:110)
      	at hudson.model.ResourceController.execute(ResourceController.java:98)
      	at hudson.model.Executor.run(Executor.java:410)
      

      It looks like jgit is used by default, but I don't have it in "Manage Jenkins" I have only command line git, which should be used.

          [JENKINS-33983] Multibranch Pipeline with git uses jgit, but should use git installation that is configured

          D Claus added a comment -

          So to further elaborate on this, a workaround is to go into "Manage Jenkins" -> "Global Tool Configuration" then under "Git" click "Add Git" then select "JGit". See also https://wiki.jenkins-ci.org/display/JENKINS/Git+plugin+2.0+beta+testing#Gitplugin2.0betatesting-ActivatingJGit.

          The attached links says "go to the system configuration page" which should read "go into the Global Tool Configuration page".

          D Claus added a comment - So to further elaborate on this, a workaround is to go into "Manage Jenkins" -> "Global Tool Configuration" then under "Git" click "Add Git" then select "JGit". See also https://wiki.jenkins-ci.org/display/JENKINS/Git+plugin+2.0+beta+testing#Gitplugin2.0betatesting-ActivatingJGit . The attached links says "go to the system configuration page" which should read "go into the Global Tool Configuration page".

          Jesse Glick added a comment -

          Generally, GitSCMSource should allow GitInstallation selection.

          Jesse Glick added a comment - Generally, GitSCMSource should allow GitInstallation selection.

          Jesse Glick added a comment -

          That said, I do not know why you encountered this error. Both CLI Git and JGit support SSH private key authentication. Did you specify your private key under Credentials in the SCM source configuration?

          Jesse Glick added a comment - That said, I do not know why you encountered this error. Both CLI Git and JGit support SSH private key authentication. Did you specify your private key under Credentials in the SCM source configuration?

          dc00, the problems seems to be that JGit is used, so configuring Jenkins explicitly to use JGit will likely not fix that. I am running into the same problem as the requester has, JGit is used despite I have only one git configuration and that is a local one (that works from console).

          Oliver Gondža added a comment - dc00 , the problems seems to be that JGit is used, so configuring Jenkins explicitly to use JGit will likely not fix that. I am running into the same problem as the requester has, JGit is used despite I have only one git configuration and that is a local one (that works from console).

          Nghia Le Van added a comment -

          I have same this problem.

          Nghia Le Van added a comment - I have same this problem.

          Raino Kolk added a comment - - edited

          I had same issue.
          Seems that it is related somehow how you defined git credentials in jenkins.
          No problem if you copied PK directly to credential.
          No problem if you give full path of private key: /usr/lib/jenkins/.ssh/id_rsa for example
          Problem occured when using relative path ~/.ssh/id_rsa

          Hope this helps someone

          Raino Kolk added a comment - - edited I had same issue. Seems that it is related somehow how you defined git credentials in jenkins. No problem if you copied PK directly to credential. No problem if you give full path of private key: /usr/lib/jenkins/.ssh/id_rsa for example Problem occured when using relative path ~/.ssh/id_rsa Hope this helps someone

          Ben Fortuna added a comment - - edited

          jglick I have a dependency on CLI git as we use an SSH over HTTP tunneling config. I don't think JGit is able to support this..

          EDIT: There is an open ticket on support extra SSH options in JGit also - JENKINS-28351

          Ben Fortuna added a comment - - edited jglick I have a dependency on CLI git as we use an SSH over HTTP tunneling config. I don't think JGit is able to support this.. EDIT: There is an open ticket on support extra SSH options in JGit also - JENKINS-28351

          Pull request attached

          Jakub Cechacek added a comment - Pull request attached

          Mark Waite added a comment -

          Included in git plugin 2.6.0, released 2 Sep 2016.

          Mark Waite added a comment - Included in git plugin 2.6.0 , released 2 Sep 2016.

            jcechace Jakub Cechacek
            krzyk krzyk
            Votes:
            6 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: