Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins Git plugin with https

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:[email protected]/git/MyProject.git) however in all cases I'm still getting the same error. Any ideas?

like image 281
Christina Avatar asked Oct 24 '13 09:10

Christina


2 Answers

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 ;) )

like image 190
jimpic Avatar answered Oct 16 '22 03:10

jimpic


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.

like image 7
mgr32 Avatar answered Oct 16 '22 05:10

mgr32