15

I am trying to configure a Git project in Jenkins using the Git plugin. In the project configuration page I enter the repository URL in the Git configuration, which is an https URL (https://git.mycompany.com/git/MyProject.git). When I'm building the project however I get the following error:

Started by user Hudson Administrator
[EnvInject] - Loading node environment variables.
Building in workspace /home/hudson/.hudson/jobs/MyProject/workspace
Checkout:workspace / /home/hudson/.hudson/jobs/MyProject/workspace - hudson.remoting.LocalChannel@3699cfcc
Using strategy: Default
Cloning the remote Git repository
Cloning repository https://git.mycompany.com/git/MyProject.git
git --version
git version 1.8.2.1
ERROR: Error cloning remote repo 'origin' : Could not clone https://git.mycompany.com/git/MyProject.git
hudson.plugins.git.GitException: Could not clone https://git.mycompany.com/git/MyProject.git
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:286)
    at org.jenkinsci.plugins.gitclient.AbstractGitAPIImpl.clone(AbstractGitAPIImpl.java:59)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.clone(CliGitAPIImpl.java:47)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1012)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:948)
    at hudson.FilePath.act(FilePath.java:912)
    at hudson.FilePath.act(FilePath.java:885)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:948)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1114)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1411)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:652)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:557)
    at hudson.model.Run.execute(Run.java:1665)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:507)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:230)
Caused by: hudson.plugins.git.GitException: Failed to connect to https://git.mycompany.com/git/MyProject.git
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getURLWithCrendentials(CliGitAPIImpl.java:1374)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.getURLWithCrendentials(CliGitAPIImpl.java:1326)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$300(CliGitAPIImpl.java:47)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:280)
    ... 16 more
Trying next repository
ERROR: Could not clone repository
java.io.IOException: Could not clone
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1025)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:948)
    at hudson.FilePath.act(FilePath.java:912)
    at hudson.FilePath.act(FilePath.java:885)
    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:948)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1114)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1411)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:652)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:557)
    at hudson.model.Run.execute(Run.java:1665)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:507)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:230)

I can clone the repository from the command line, as well as by executing git clone as a shell command in the Jenkins project pre-build steps, so I'm at a loss on why the plugin configuration doesn't work. Thinking it might be an authentication issue I tried specifying the credentials in a .netrc file as well as including them in the URL (ie. https://username:password@git.mycompany.com/git/MyProject.git) however in all cases I'm still getting the same error. Any ideas?

Christina
  • 3,562
  • 3
  • 22
  • 32
  • One possible reason is that Jenkins couldn't accept your ssl certificate (maybe it is not for domain you use) – tijs Oct 24 '13 at 16:37
  • It's true that I currently have a problem with the SSL certificate, which is why I have added sslVeridy=false in the global .gitconfig. Does Jenkins not take this into account? Is there a different configuration? – Christina Oct 24 '13 at 16:46
  • 1
    As Jenkins is written on Java, it uses Java's list of accepted certificates, so maybe you just need to add it to that storage. Here's some workaround: http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/ – tijs Oct 24 '13 at 17:06
  • I exported the certificate from my browser and used the java keytool to add it to the keystore (cacerts) but I don't see any change. – Christina Oct 25 '13 at 06:54
  • 2
    I am seeing the same problem. This is imho a bug in the jenkins git plugin. When you set to use JGit in the jenkins config, you can get it to work. Or use SSH. It worked in previous versions (some months ago). – jimpic Oct 28 '13 at 17:36
  • 1
    @jimpic It seems this is the case after all. I also tested access to a public Git repository (to make sure it wasn't a problem with the way I was passing credentials) and it still didn't work so I guess the only option left is a bug of the plugin. If you post this as an answer (with perhaps a few more details on possible workarounds) I'll be happy to accept it. – Christina Oct 30 '13 at 07:04
  • thx for asking this question and posting the comments. i just wasted a week trying to figure out what the heck was happening just to find out it's a plugin issue. darn you git plugin!! (says the ungrateful user of the free plugin). i'll upvote any answer @jimpic posts here too. P.S. is there a bug filed yet? i'll file a bug if there isn't any. – Classified Nov 04 '13 at 17:23

11 Answers11

17

This is a bug in the Jenkins Git Plugin.

You can workaround the credential issue by creating credentials using the credential plugin and then use these credentials in the SCM/Git section of your Job. However, this will expose your user/password in plaintext in the build log if the checkout fails.

Also, this will not work if you are using a HTTP proxy with git. The best way (for now) is to use JGit (to be configured in the Jenkins configuration). However, JGit is experimental and very limited as well when it comes to proxies.

(answer posted due to popular request ;) )

jimpic
  • 5,360
  • 2
  • 28
  • 37
  • do you know if there's an issue open about this? – eis Nov 04 '13 at 20:04
  • +1 for confirming it's a bug with the plugin. at least i'm not going crazy :) do you have a Jenkins bug id and/or the progress of the fix? i found several bugs that look like what i'm experiencing (I can post a few if needed), but it doesn't look exactly like mine so i wasn't sure the progress. Heck, one even said "Not a defect" – Classified Nov 04 '13 at 20:47
  • I am not aware of an open ticket, I don't have an account there so I didn't create one - if somebody can do this, that would be great :) – jimpic Nov 05 '13 at 09:48
  • 1
    So, where we are ? Is this a bug ? If bug then is it resolved or not ? – Kundan Ray Dec 30 '15 at 10:34
7

In case you're using a self-signed certificate for your Git repository and Git works from command line but not from Jenkins Git Client plugin, you need to add the certificate to the Jenkins Java Keystore (as described by tijs in the comment above).

This is because Git Client plugin tries to connect directly using Java's Apache HttpClient (bypassing git.exe), so all Git settings normally used to create the connection are ignored (including GIT_SSL_NO_VERIFY and certificates in curl-ca-bundle.crt). The HttpClient throwsSunCertPathBuilderException: unable to find valid certification path to requested target which is unfortunately wrapped in a GitException without stack trace, so all we can see is 'Failed to connect' message.

In order to fix it you can follow the link provided by tijs: http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/

You would need to copy the resulting jssecacerts file to C:\Program Files (x86)\Jenkins\jre\lib\security if you're using default Jenkins installation.

You can find a link to InstallCert.java in the original Andreas Sterbenz post (thanks to web.archive.org), or a slightly modified version at code.google.

I checked the above approach works for Git Client plugin version 1.4.6.

Community
  • 1
  • 1
mgr32
  • 386
  • 1
  • 6
  • Have not verified it in Jenkins, but for Teamcity a simpler approach also works - just run the following in Jenkins' jre dir: bin\keytool -Import -Noprompt -Keystore lib\security\cacerts -Deststorepass changeit -Alias -File – mgr32 Feb 11 '15 at 08:34
2

Upgrade your Git client to 2.10.0 or up.

execute below commands.

git config --system http.sslVerify false    
git config --global http.sslVerify false    
Uwe
  • 41,420
  • 11
  • 90
  • 134
Jenish Patel
  • 154
  • 8
1

Main page of git plugin has this to say:

If you are seeing output indicating Git could not clone, something like the output below, go to to the Jenkins configuration settings (not the project settings, the global ones) and change the Git path to a fully qualified path (eg. not "git" but "/usr/bin/git" or wherever your Git binary is installed). You should also verify that the permissions are correct if you are doing a file system based clone.

Started by user anonymous
Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370
Last Build : #4
Checkout:workspace / C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace - hudson.remoting.LocalChannel@1a1f370
Cloning the remote Git repository
Cloning repository origin
$ git clone -o origin git://github.com/bret/watir.git "C:\Documents and Settings\Administrator\.hudson\jobs\watir\workspace"
Trying next repository
ERROR: Could not clone from a repository
FATAL: Could not clone
hudson.plugins.git.GitException: Could not clone
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:400)
    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:358)
    at hudson.FilePath.act(FilePath.java:676)
    at hudson.FilePath.act(FilePath.java:660)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:358)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:833)
    at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:314)
    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:266)
    at hudson.model.Run.run(Run.java:948)
    at hudson.model.Build.run(Build.java:112)
    at hudson.model.ResourceController.execute(ResourceController.java:93)
    at hudson.model.Executor.run(Executor.java:118)

This might be an issue for you too.

The same page also suggests testing with JGit if there's an issue with default plugin behaviour(-Dorg.jenkinsci.plugins.gitclient.Git.useCLI=false).

eis
  • 51,991
  • 13
  • 150
  • 199
1

In order to use Git in Jenkins, the following two plugins need to be installed:

  1. Git-Client-plugin
  2. Git-plugin

The first plugin (Git-Client-plugin) is a low-level API to execute git operations (git add, git commit, git push ,git clone,..etc).

The second plugin (Git-plugin) adds Git as an SCM option for Jenkins jobs.

The second plugin relies on functionality from the first plugin, and so both must be present for Git to work with Jenkins.

mahinlma
  • 1,208
  • 3
  • 11
  • 24
1

You can register your git credentials in "Credentials" with your login and password to access the git repository by https protocol (below of "Manage Jenkins"), it will generate a credentialId (e.g. dd0d6733-cc2e-4464-bb7d-4b6af86fe40a) that helps Jenkins to use this credential in pipelines.

When you use Jenkins Pipeline, you can do:

node{
    git url: "https://tfs:8080/tfs/job.git", branch: "feature/migration", credentialsId:'dd0d6733-cc2e-4464-bb7d-4b6af86fe40a'
}

It will download your source codes to the job's workspace

Lucas Amorim Silva
  • 567
  • 1
  • 7
  • 14
0

I tried all stuff to get rid of certificate issue but then finally it is issue with git plugin. I roll back plugins to git 1.5 (from 2.0.3) and git-client 1.0.7 (from 1.6.3) and it worked find. Note that I tried git-client 1.4.6 first so that I can use credential option but it didn't work. So I think correct combination of these 2 plugins are important. This solution was mentioned at JENKINS-20533

ashah
  • 169
  • 2
  • 12
0

In my case, one Jenkins slave worked normally, while another did not. When I changed the Git executable from default to JGit, they both worked.

Adil
  • 2,092
  • 3
  • 25
  • 35
0

This is now fixed and no more an issue with up to date plugin (as I'm writing this 1.19.0). It happened with git-plugin-client 1.6.x.

kriss
  • 23,497
  • 17
  • 97
  • 116
0

using git:// instead of https:// works for me on jenkins 1.644 with git client 1.19.6

fredericrous
  • 2,833
  • 1
  • 25
  • 26
0

My solution did works well for Jenkins-Git-Plugin.

# create my exec
su root
darngit=/usr/bin/darngit
touch $darngit
echo "#! /usr/bin/env bash" > $darngit
echo "git -c sslVerify=false $@" > $darngit

Goto system setting, set git executable = /usr/bin/darngit

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
micfan
  • 800
  • 8
  • 12