使用https的Jenkins Git插件

Chr*_*ina 15 git jenkins jenkins-plugins

我正在尝试使用Git插件在Jenkins中配置Git项目.在项目配置页面中,我在Git配置中输入存储库URL,这是一个https URL(https://git.mycompany.com/git/MyProject.git).当我正在构建项目时,我收到以下错误:

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)
Run Code Online (Sandbox Code Playgroud)

我可以从命令行克隆存储库,也可以git clone在Jenkins项目预构建步骤中执行shell命令,因此我对插件配置不起作用的原因感到茫然.认为这可能是一个身份验证问题我尝试在.netrc文件中指定凭据,并将它们包含在URL中(即https:// username:password@git.mycompany.com/git/MyProject.git)但是在所有情况我仍然得到同样的错误.有任何想法吗?

jim*_*pic 16

这是Jenkins Git插件中的一个错误.

您可以通过使用凭据插件创建凭据来解决凭据问题,然后在作业的SCM/Git部分中使用这些凭据.但是,如果结帐失败,这将在构建日志中以纯文本显示您的用户/密码.

此外,如果您使用带git的HTTP代理,这将不起作用.最好的方法(现在)是使用JGit(在Jenkins配置中配置).然而,JGit是实验性的,并且在代理方面也非常有限.

(由于受欢迎的要求发布了答案;))


小智 7

如果您使用的是自签名证书,以便Git仓库和Git的命令行工作,但不能从詹金斯Git的客户端插件,您需要将证书添加到詹金斯Java密钥(被描述tijs评论上述) .

这是因为Git Client插件尝试使用Java的Apache HttpClient直接连接(绕过git.exe),因此通常用于创建连接的所有Git设置都会被忽略(包括GIT_SSL_NO_VERIFY和证书.HttpClient curl-ca-bundle.crt)抛出SunCertPathBuilderException: unable to find valid certification path to requested target哪个不幸包裹在GitException中而没有堆栈跟踪,所以我们所能看到的是"连接失败"消息.

为了解决这个问题,您可以按照tijs提供的链接进行操作:http: //www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/

如果您使用的是默认的Jenkins安装jssecacerts,C:\Program Files (x86)\Jenkins\jre\lib\security则需要将生成的文件复制到.

您可以InstallCert.java在原始的Andreas Sterbenz帖子中找到一个链接(感谢web.archive.org),或者在code.google上找到稍加修改的版本.

我检查了上面的方法适用于Git Client插件版本1.4.6.