最近须要在Jenkins上配置一个Job,SCM源是http://git.opendaylight.org/gerrit/p/integration.git
因而使用Jenkins的Git Plugin作这件事情。
结果报错以下:java
hudson.plugins.git.GitException: Failed to fetch from https://git.opendaylight.org/gerrit/p/integration.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:627)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:865)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:890)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1415)
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:561)
at hudson.model.Run.execute(Run.java:1678)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:231)
Caused by: hudson.plugins.git.GitException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.checkCredentials(CliGitAPIImpl.java:2198)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1152)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:266)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:625)
... 10 more
可是直接在命令行中运行git clone是好的,那么差异在哪里呢?在网上查了一下,获得了一些思路,即Jenkins总体是构建在Java之上的,在进入git接管的范围以前,是Java在作一些事情,既然git自己是能够工做的,那么应该就是Java这边出的问题。
查了下具体的错误,发现跟SSL/TSL证书有关。看到StackOverflow上有同志说是git plugin自己有bug就不能支持https,我以为应该不至于吧,查看了git plugin的主页(https://wiki.jenkins-ci.org/display/JENKINS/Git+Plugin)也没有发现什么端倪。因而又随便尝试了一下github上的某个https的git库,是能够clone下来的,这就说明支持https是没问题的。那么问题出在哪里呢?从新复习了一下SSL/TSL的原理以后,认为问题应该出在颁发证书的CA上,因而在浏览器中去查看两者的CA有何不一样,以下:git
github使用的是DigiCert的证书,而opendaylight用的是StartCom的。上网一查,这个StartCom颁发的整数竟然是免费的。这样看来,缘由大概就是Java不信任这个CA了。那么解决方法应该就是把这个CA添加到Java的信任列表。具体作法以下:
1. 首先要获得StartCom的证书文件(xxx.cer)。从哪里得到呢?既然浏览器可以正常访问,说明系统中是信任StartCom的证书的,因此先打开系统的证书管理界面。在Mac中是Keychain,打开以后找到StartCom的证书,而后右键导出成一个.cer文件,命名为startcom.cer。github
2. 而后使用下面的命令把上面那个cer文件导入到Java的运行时系统中:浏览器
keytool -import -alias startcom -keystore %JRE_HOME/lib/security/cacerts -file startcom.cer
运行该命令时会提示输入密码,若是你没有改过的话密码是’changeit’
而后再运行下面的命令,就能够看到StartCom已经被加进去了。less
keytool -list -keystore %JRE_HOME/lib/security/cacerts | less
而后在在Jenkins中配置git路径,git clone成功!
ide