首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么Jenkins中的GIT插件不能连接到GIT存储库?

为什么Jenkins中的GIT插件不能连接到GIT存储库?
EN

Stack Overflow用户
提问于 2017-01-19 20:24:40
回答 3查看 23.4K关注 0票数 6

我正在尝试使用GIT插件Jenkins从GIT中拉出代码,该作业正在从属机器上运行。

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

并且在SLAVE系统中没有定义http_proxy

每当我在SLAVE机器上本地进行git克隆时,它都能完美地工作,但是在Jenkins上我并没有成功。

它抛出以下错误:

代码语言:javascript
运行
复制
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代理?

若有,如何预防?

或者,我还遗漏了什么吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-01-20 17:15:01

原来这是个代理问题。

当使用Jenkins从GIT中提取代码时,它将http_proxy设置为mycom.domain.com:80 (MASTER机器代理),而这个代理在SLAVE机器中不是必需的。

所以,我刚刚在Jenkins的No Proxy Host部分(Manage Jenkins -> Manage Plugins -> Advanced -> HTTP Proxy Configuration -> Added GIT URL in No Proxy Host field)中添加了GIT URL,现在它工作得很好。

票数 1
EN

Stack Overflow用户

发布于 2017-01-19 21:04:11

在拉取工程之前,请尝试在全局配置中设置HTTP代理:

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

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

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

票数 2
EN

Stack Overflow用户

发布于 2017-01-19 21:38:27

今天我也用git仓库建立了jenkins,对我很有用,希望这能有所帮助。

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

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

1.创建作业名称

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

3.点击OK

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

步骤3。如果您将看到如下错误

无法连接到存储库:命令"git ls-remote -h git@example.git HEAD“返回状态代码128: stdout: stderr: fatal:'git@example.git‘似乎不是git存储库fatal:远程端意外挂起

你需要做更多的配置:

1.转到终端

2.运行以下命令:sudo visudo

3.添加%jenkins ALL=NOPASSWD:此文件中的所有sudo previlage为defined.and关闭该文件。

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

5.在jenkins主目录中创建一个.ssh目录。

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

生成SSH密钥:

SSH1:密钥的检查

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

cd ~/.ssh检查用户目录中是否存在名为".ssh“的目录

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

SSH2:生成新的密钥

要生成新的SSH密钥,请输入以下代码。我们需要默认设置,因此当要求输入保存密钥的文件时,只需按enter键即可。

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

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

这应该会给你类似这样的结果:

您的标识已保存在/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

SSH3:将您的密钥添加到GitHub

转到您的帐户设置

4 :源管理标签下的

代码语言:javascript
运行
复制
       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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41741762

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档