使用https的Jenkins Git插件

时间:2013-10-24 09:07:41

标签: 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)

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

11 个答案:

答案 0 :(得分:15)

这是Jenkins Git Plugin中的错误。

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

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

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

答案 1 :(得分:6)

如果您为Git存储库使用自签名证书而Git从命令行使用而不是从Jenkins Git客户端插件工作,则需要将证书添加到Jenkins Java密钥库(如所述) comment above)中的tijs

这是因为Git Client插件尝试使用Java的Apache HttpClient直接连接(绕过git.exe),因此忽略了通常用于创建连接的所有Git设置(包括GIT_SSL_NO_VERIFYcurl-ca-bundle.crt)中的证书HttpClient抛出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

您可以在原Andreas Sterbenz post找到InstallCert.java的链接(感谢web.archive.org),或code.google稍加修改的版本。

我检查了上述方法适用于Git Client插件版本1.4.6。

答案 2 :(得分:2)

将您的Git客户端升级到2.10.0或更高版本。

执行以下命令。

git config --system http.sslVerify false    
git config --global http.sslVerify false    

答案 3 :(得分:1)

Main page of git plugin有这样的说法:

  

如果你看到输出指示Git无法克隆,那么   如下面的输出,转到Jenkins配置设置   (不是项目设置,全局设置)并将Git路径更改为   完全合格的路径(例如,不是“git”,而是“/ usr / bin / git”或任何地方   你的Git二进制文件已安装)。你还应该验证一下   如果您正在执行基于文件系统的克隆,则权限是正确的。

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)

这也可能是一个问题。

如果出现默认插件行为问题(-Dorg.jenkinsci.plugins.gitclient.Git.useCLI=false),同一页面还建议使用JGit进行测试。

答案 4 :(得分:1)

您可以使用登录密码“凭据”中注册 git凭据,以访问git存储库由 https协议(在“管理Jenkins”下面),它将生成 credentialId (例如 dd0d6733-cc2e-4464-bb7d-4b6af86fe40a )这有助于Jenkins在管道中使用此凭据。

使用 Jenkins Pipeline 时,您可以执行以下操作:

node{
    git url: "https://tfs:8080/tfs/job.git", branch: "feature/migration", credentialsId:'dd0d6733-cc2e-4464-bb7d-4b6af86fe40a'
}

它会将您的源代码下载到作业的工作区

答案 5 :(得分:1)

我的解决方案适用于Jenkins-Git-Plugin。

<config condition="DocLibActions" evaluator="string-compare">
    <actions>
        <action...>         
            <!-- Custom evaluator -->
            <evaluator>my.custom.evaluator</evaluator>
       </action>
    </actions>
</config>

转到系统设置,设置git executable = # create my exec su root fuckgit=/usr/bin/fuckgit touch $fuckgit echo "#! /usr/bin/env bash" > $fuckgit echo "git -c sslVerify=false $@" > $fuckgit

完成。

TODO:漂亮的这个ans

答案 6 :(得分:0)

我尝试了所有的东西来摆脱证书问题,但最后它是git插件的问题。我将插件回滚到git 1.5(从2.0.3开始)和git-client 1.0.7(从1.6.3开始)并且它可以找到。请注意,我首先尝试了git-client 1.4.6,以便我可以使用凭证选项,但它不起作用。所以我认为这两个插件的正确组合很重要。 JENKINS-20533

提到了这个解决方案

答案 7 :(得分:0)

为了在Jenkins中使用Git,需要安装以下两个插件:

  1. GIT中-客户插件
  2. GIT中-插件
  3. 第一个插件(Git-Client-plugin)是一个执行git操作的低级API(git add,git commit,git push,git clone,..等)。

    第二个插件(Git-plugin)将Git添加为Jenkins作业的SCM选项。

    第二个插件依赖于第一个插件的功能,因此Git必须同时存在才能与Jenkins一起使用。

答案 8 :(得分:0)

在我的情况下,一个詹金斯奴隶正常工作,而另一个没有。当我将Git可执行文件从默认更改为JGit时,它们都有效。

答案 9 :(得分:0)

现在这已经修复,不再是最新插件的问题(因为我正在写这个1.19.0)。它发生在git-plugin-client 1.6.x。

答案 10 :(得分:0)

使用git://而不是https://使用git client 1.19.6在jenkins 1.644上为我工作