最近在将Jenkins内部使用的git和git client两个plugin分别升级到2.2(from 1.4), 1.9.1以后,git plugin 用https访问 git repo报错:
> git --version
using GIT_SSH to set credentials
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: com.ibm.jsse2.util.j: PKIX path building failed: java.security.cert.CertPathBuilderException: PKIXCertPathBuilderImpl could not build a valid CertPath.; internal cause is:
java.security.cert.CertPathValidatorException: The certificate issued by CN=IBM Internal Root CA, O=International Business Machines Corporation, C=US is not trusted; internal cause is:
java.security.cert.CertPathValidatorException: Certificate chaining error
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.checkCredentials(CliGitAPIImpl.java:1982)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1143)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$200(CliGitAPIImpl.java:87)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:257)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:413)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:153)
at org.jenkinsci.plugins.gitclient.RemoteGitImpl$CommandInvocationHandler$1.call(RemoteGitImpl.java:146)
at hudson.remoting.UserRequest.perform(UserRequest.java:118)
at hudson.remoting.UserRequest.perform(UserRequest.java:48)
at hudson.remoting.Request$2.run(Request.java:326)
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
at java.util.concurrent.FutureTask.run(FutureTask.java:149)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:906)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:929)
at java.lang.Thread.run(Thread.java:761)
1) vi /etc/default/Jenkins;
2) /etc/init.d/Jenkins restart,记住对采用master-slave结构的jenkins cluster环境Jenkins slave也需要加入该选项支持
5. 发现即使enable untrustedSSL还是报错,研究后发现这是jenkins client的一个bug(见https://issues.jenkins-ci.org/browse/JENKINS-22675 )
修复之前
if(acceptSelfSignedCertificates && "https".equalsIgnoreCase(u.getScheme())) {
final SSLContextBuilder contextBuilder = SSLContexts.custom();
try {
contextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
} catch (NoSuchAlgorithmException e) {
throw new GitException(e.getLocalizedMessage(), e);
} catch (KeyStoreException e) {
throw new GitException(e.getLocalizedMessage(), e);
}
SSLContext sslContext = null;
try {
sslContext = contextBuilder.build();
} catch (KeyManagementException e) {
throw new GitException(e.getLocalizedMessage(), e);
} catch (NoSuchAlgorithmException e) {
throw new GitException(e.getLocalizedMessage(), e);
}
clientBuilder.setSslcontext(sslContext);
}
修复之后:
if(acceptSelfSignedCertificates && "https".equalsIgnoreCase(u.getScheme())) {
final SSLContextBuilder contextBuilder = SSLContexts.custom();
try {
contextBuilder.loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
return true;
}
}););
} catch (NoSuchAlgorithmException e) {
throw new GitException(e.getLocalizedMessage(), e);
} catch (KeyStoreException e) {
throw new GitException(e.getLocalizedMessage(), e);
}
SSLContext sslContext = null;
try {
sslContext = contextBuilder.build();
} catch (KeyManagementException e) {
throw new GitException(e.getLocalizedMessage(), e);
} catch (NoSuchAlgorithmException e) {
throw new GitException(e.getLocalizedMessage(), e);
}
clientBuilder.setSslcontext(sslContext);
}
/**
* A trust strategy that accepts self-signed certificates as trusted. Verification of all other
* certificates is done by the trust manager configured in the SSL context.
*
* @since 4.1
*/
public class TrustSelfSignedStrategy implements TrustStrategy {
public boolean isTrusted(
final X509Certificate[] chain, final String authType) throws CertificateException {
return chain.length == 1;
}
}
git clone htpps://github.com/jenkinsci/git-client-plugin
git checkout git-client-1.9.1
mvn compile
mvn package
下面是配置ssh方式的步骤:
1.新建credential并填入private key
2.在需要访问的git project中enble jenknis_deploy的deployment key.(实际上是public key)