【问题标题】:Why GIT Plugin in Jenkins is not able to connect to the GIT Repository?为什么 Jenkins 中的 GIT 插件无法连接到 GIT 存储库?
【发布时间】:2017-06-04 03:36:34
【问题描述】:

我正在尝试使用 GIT Plugin Jenkins 从 GIT 中提取代码,并且该作业正在从属计算机上运行。

MASTER系统有http_proxy=mycom.domain.com:80

SLAVE 系统中没有定义http_proxy

每当我在 SLAVE 机器上本地执行 git clone 时,它​​都能完美运行,但是从 Jenkins 那里我没有成功。

它抛出以下错误:

Building remotely on SLAVE in workspace /data/test
 > /usr/bin/git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > /usr/bin/git config remote.origin.url https://github.domain.com/Project-Digital/Project-eCommerce.git # timeout=10
Fetching upstream changes from https://github.domain.com/Project-Digital/Project-eCommerce.git
 > /usr/bin/git --version # timeout=10
using GIT_ASKPASS to set credentials 
Setting http proxy: mycom.domain.com:80
 > /usr/bin/git fetch --tags --progress https://github.domain.com/Project-Digital/Project-eCommerce.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from https://github.domain.com/Project-Digital/Project-eCommerce.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:803)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1063)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1094)
    at hudson.scm.SCM.checkout(SCM.java:495)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1278)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:604)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:529)
    at hudson.model.Run.execute(Run.java:1728)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Caused by: hudson.plugins.git.GitException: Command "/usr/bin/git fetch --tags --progress https://github.domain.com/Project-Digital/Project-eCommerce.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: error: Failed connect to github.build.ge.com:80; Operation now in progress while accessing https://github.domain.com/Project-Digital/Project-eCommerce.git/info/refs

是不是因为MASTER 系统试图设置SLAVE 系统中不存在的http 代理?

如果是,如何预防?

或者,我还有什么遗漏的吗?

【问题讨论】:

    标签: git github jenkins devops


    【解决方案1】:

    今天我还用git仓库设置了jenkins,为我工作,希望对你有帮助,

    要将 git 与 jenkins 连接,请执行以下步骤:

    第 1 步。成功安装插件后,创建一个新作业,如下所示:

    1.创建作业名称

    2.勾选Build a maven software project的单选按钮

    3.点击确定

    第 2 步。现在选中 Git 的单选按钮,输入您的 git 存储库的 uri。

    第 3 步。如果您会看到类似的错误

    无法连接到存储库:命令“git ls-remote -h git@example.git HEAD”返回状态码 128: 标准输出: 标准错误:致命:“git@example.git”似乎不是 git 存储库 致命:远端意外挂断

    你必须做一些更多的配置:

    1.转到终端

    2.运行这个命令:sudo visudo

    3.在这个定义了sudo previlage的文件中添加%jenkins ALL=NOPASSWD: ALL。然后关闭文件。

    4.通过命令以 jenkins 用户身份登录:sudo su jenkins

    5.在jenkins主目录下创建.ssh目录。

    6.像这样创建公钥私钥对。

    生成 SSH 密钥:

    1:检查 SSH 密钥

    首先,我们需要检查您计算机上现有的 ssh 密钥。打开终端并运行:

    cd ~/.ssh 检查您的用户目录中是否有一个名为“.ssh”的目录

    如果显示“没有这样的文件或目录”,请转到第 2 步。否则,您已经有一个现有的密钥对,您可以跳到第 3 步。

    2:生成新的 SSH 密钥

    要生成新的 SSH 密钥,请输入以下代码。我们想要默认设置,所以当被要求输入保存密钥的文件时,只需按 Enter。

    ssh-keygen -t rsa -C "your_email@example.com"

    创建一个新的 ssh 密钥,使用提供的电子邮件作为标签生成公钥/私钥 rsa 密钥对。输入保存密钥的文件(/home/you/.ssh/id_rsa): 现在您需要输入密码或文件。按回车无需写入任何内容。

    这应该给你这样的东西:

    您的身份已保存在 /home/you/.ssh/id_rsa 中。

    您的公钥已保存在 /home/you/.ssh/id_rsa.pub。 密钥指纹是:

    01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com

    3:将 SSH 密钥添加到 GitHub

    转到您的帐户设置

    4 : 在 Source Management 标签下,

           Build Triggers- Build whenever a SNAPSHOT dependency is built
           Root POM-  /var/lib/jenkins/jobs/ProjectName/workspace/ProjectName/pom.xml
    

    在 Execute Shell 标签下你可以把你的脚本执行。

    最后点击 Build Now 创建构建,打开控制台查看状态。

    【讨论】:

    【解决方案2】:

    拉取项目前,尝试在全局配置中设置HTTP代理:

    $> git config --global http.proxy http://mycom.example.com:80

    如果您需要为您的代理提供用户名和密码,您可以使用:

    $> git config --global http.proxy http://example.com\\<yourUsername>:<yourPassword>@<yourProxyServer>:80

    【讨论】:

      【解决方案3】:

      原来是代理问题。

      在使用 Jenkins 从 GIT 中提取代码时,它会将 http_proxy 设置为 mycom.domain.com:80MASTER 机器代理),而 SLAVE 机器中不需要此代理。

      所以,我刚刚在 Jenkins 中将 GIT URL 添加到 No Proxy Host 部分 (Manage Jenkins -> Manage Plugins -> Advanced -> HTTP Proxy Configuration -> Added GIT URL in No Proxy Host field),现在它工作正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-05-12
        • 1970-01-01
        • 1970-01-01
        • 2020-07-03
        • 1970-01-01
        • 2013-01-05
        • 1970-01-01
        • 2014-05-14
        相关资源
        最近更新 更多