问题
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?
回答1:
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 ;) )
回答2:
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.
回答3:
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
回答4:
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
).
回答5:
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
回答6:
My solution did works well for Jenkins-Git-Plugin.
# create my exec
su root
fuckgit=/usr/bin/fuckgit
touch $fuckgit
echo "#! /usr/bin/env bash" > $fuckgit
echo "git -c sslVerify=false $@" > $fuckgit
Goto system setting, set git executable = /usr/bin/fuckgit
Done.
TODO: beautiful this ans
回答7:
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
回答8:
In order to use Git in Jenkins, the following two plugins need to be installed:
- Git-Client-plugin
- 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.
回答9:
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.
回答10:
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.
回答11:
using git:// instead of https:// works for me on jenkins 1.644 with git client 1.19.6
来源:https://stackoverflow.com/questions/19561570/jenkins-git-plugin-with-https