为什么 Jenkins 中的 GIT 插件无法连接到 GIT 存储库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41741762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why GIT Plugin in Jenkins is not able to connect to the GIT Repository?
提问by ANIL
I am trying to pull the code form GIT using GIT Plugin Jenkins and the job is running on a slave machine.
我正在尝试使用 GIT 插件 Jenkins 从 GIT 中提取代码,并且该作业正在从属计算机上运行。
MASTER
system has http_proxy=mycom.domain.com:80
MASTER
系统有 http_proxy=mycom.domain.com:80
and in SLAVE
system there is no http_proxy
defined.
并且在SLAVE
系统中没有http_proxy
定义。
Whenever I am doing git clone locally in the SLAVE
machine it works perfectly, however from Jenkins I haven't been successful.
每当我在SLAVE
机器上本地执行 git clone 时,它都能完美运行,但是在 Jenkins 中我并没有成功。
It is throwing the following error:
它抛出以下错误:
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
Is it because the MASTER
system trying to set http proxy which is not present in the SLAVE
system?
是不是因为MASTER
系统试图设置系统中不存在的http代理SLAVE
?
If yes, how to prevent it?
如果是,如何预防?
Or, is there something else I am missing?
或者,还有什么我想念的吗?
采纳答案by ANIL
Turned out it was a proxy issue.
原来是代理问题。
While pulling the code from GIT using Jenkins it was setting the http_proxy
to mycom.domain.com:80
(MASTER
machine proxy) and this proxy was not required in the SLAVE
machine.
当使用从詹金斯GIT拉动代码它被设置http_proxy
到mycom.domain.com:80
(MASTER
机代理),并在未要求该代理SLAVE
机。
So, I just added the GIT URL to No Proxy Host section (Manage Jenkins -> Manage Plugins -> Advanced -> HTTP Proxy Configuration -> Added GIT URL in No Proxy Host field)
in Jenkins and now it is working fine.
所以,我刚刚将 GIT URL 添加到(Manage Jenkins -> Manage Plugins -> Advanced -> HTTP Proxy Configuration -> Added GIT URL in No Proxy Host field)
Jenkins 的No Proxy Host 部分,现在它工作正常。
回答by Ala Eddine JEBALI
Before pulling the project, try to set the HTTP proxy in global configuration:
在拉项目之前,尝试在全局配置中设置HTTP代理:
$> git config --global http.proxy http://mycom.example.com:80
$> git config --global http.proxy http://mycom.example.com:80
If you need to provide a username and a password for your proxy, you can use:
如果您需要为代理提供用户名和密码,您可以使用:
$> git config --global http.proxy http://example.com\\<yourUsername>:<yourPassword>@<yourProxyServer>:80
$> git config --global http.proxy http://example.com\\<yourUsername>:<yourPassword>@<yourProxyServer>:80
回答by lazyborg
Today i also set up the jenkins with git repository, worked for me, hope this helps,
今天我还用 git 存储库设置了 jenkins,对我来说有效,希望这有帮助,
To connect git with jenkins do following steps :
要将 git 与 jenkins 连接,请执行以下步骤:
STEP 1. After successfull installation of plugins create a new job like this:
第 1 步。成功安装插件后,创建一个像这样的新工作:
1.create a Job name
1.创建作业名称
2.checked the radio button of Build a maven software project
2.勾选Build a maven software project的单选按钮
3.click OK
3.点击确定
STEP 2. Now checked the radio button for Git enter the uri of your git repository.
第 2 步。现在选中 Git 的单选按钮,输入您的 git 存储库的 uri。
STEP 3. If you will see the error like
第 3 步。如果你会看到这样的错误
Failed to connect to repository : Command "git ls-remote -h [email protected] HEAD" returned status code 128: stdout: stderr: fatal: '[email protected]' does not appear to be a git repository fatal: The remote end hung up unexpectedly
无法连接到存储库:命令“git ls-remote -h [email protected] HEAD”返回状态代码 128:stdout:stderr:fatal:'[email protected]' 似乎不是 git 存储库致命:远端意外挂断
You have to do some more configuration:
你必须做一些更多的配置:
1.Go to to the terminal
1.前往终端
2.Run this command : sudo visudo
2.运行此命令:sudo visudo
3.Add %jenkins ALL=NOPASSWD: ALL in this file where sudo previlage is defined.and close the file.
3.在此文件中添加 %jenkins ALL=NOPASSWD: ALL 定义 sudo previlage。并关闭文件。
4.login as jenkins user via command : sudo su jenkins
4.通过命令以jenkins用户身份登录:sudo su jenkins
5.Create a .ssh directory in the jenkins home directory.
5.在jenkins家目录下创建一个.ssh目录。
6.create the public private key pair like this.
6.像这样创建公钥私钥对。
Generating SSH Keys:
生成 SSH 密钥:
1:Check for SSH keys
1:检查SSH密钥
First, we need to check for existing ssh keys on your computer. Open up Terminal and run:
首先,我们需要检查您计算机上现有的 ssh 密钥。打开终端并运行:
cd ~/.sshChecks to see if there is a directory named ".ssh" in your user directory
cd ~/.ssh检查你的用户目录中是否有名为“.ssh”的目录
If it says "No such file or directory" go to step 2. Otherwise, you already have an existing keypair, and you can skip to step 3.
如果显示“没有这样的文件或目录”,请转到第 2 步。否则,您已经有一个现有的密钥对,您可以跳到第 3 步。
2: Generate a new SSH key
2:生成新的SSH密钥
To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.
要生成新的 SSH 密钥,请输入以下代码。我们需要默认设置,因此当要求输入保存密钥的文件时,只需按 Enter。
ssh-keygen -t rsa -C "[email protected]"
ssh-keygen -t rsa -C "[email protected]"
Creates a new ssh key, using the provided email as a label Generating public/private rsa key pair. Enter file in which to save the key (/home/you/.ssh/id_rsa): Now you need to enter a passphrase or file.press enter without to write any thing.
创建一个新的 ssh 密钥,使用提供的电子邮件作为标签生成公共/私有 rsa 密钥对。输入要保存密钥的文件 (/home/you/.ssh/id_rsa):现在您需要输入密码或文件。按 Enter 键无需写任何内容。
Which should give you something like this:
这应该给你这样的东西:
Your identification has been saved in /home/you/.ssh/id_rsa.
您的身明已保存在/home/you/.ssh/id_rsa 中。
Your public key has been saved in /home/you/.ssh/id_rsa.pub.The key fingerprint is:
您的公钥已保存在/home/you/.ssh/id_rsa.pub 中。关键指纹是:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]
3: Add your SSH key to GitHub
3:将您的 SSH 密钥添加到 GitHub
Go to your Account Settings
转到您的帐户设置
4 :Under Source Management tag,
4 :在源管理标签下,
Build Triggers- Build whenever a SNAPSHOT dependency is built
Root POM- /var/lib/jenkins/jobs/ProjectName/workspace/ProjectName/pom.xml
Under Execute Shell tagyou can put your scripts to execute.
在 Execute Shell 标签下,您可以将脚本执行。
Finally Click on Build Now to create the build, Open console to check the status.
最后点击 Build Now 创建构建,打开控制台检查状态。