简体   繁体   English

设置 Github Jenkins 插件时出现“无法连接到存储库”错误

[英]"Failed to connect to repository" Error while setting up Github Jenkins Plugin

I am getting an error when inputting my repo location into the "Source Code Management > Git > Repository URL" section of a new Job.将我的存储库位置输入新作业的“源代码管理 > Git > 存储库 URL”部分时出现错误。 I have searched all around and tried many different URLs with no success.我四处搜索并尝试了许多不同的 URL,但都没有成功。

Error:错误:

Failed to connect to repository : Error performing command: git ls-remote -h https://github.com/micdoodle8/Crossbow_Mod_2.git HEAD

Any ideas?有任何想法吗? Thanks.谢谢。

You might need to set the path to your git executable in Manage Jenkins -> Configure System -> Git -> Git Installations -> Path to Git executable .您可能需要在Manage Jenkins -> Configure System -> Git -> Git Installations -> Path to Git executable 中设置 git 可执行文件的路径

For example, I was getting the same error in Windows.例如,我在 Windows 中遇到了同样的错误。 I had installed git with chocolatey, and got the location via Powershell:我已经用巧克力安装了 git,并通过 Powershell 获取了位置:

Get-Command git.exe | Select Definition

In Unix, you should be able to do:在 Unix 中,您应该能够执行以下操作:

which git

on Jenkins ver.在詹金斯版上。 2.7.4, the setting property of (Path to Git executable) is now in Manage Jenkins -> Global Tool Configuration -> Git -> Git Installations -> Path to Git executable. 2.7.4,(Path to Git executable)的设置属性现在在Manage Jenkins -> Global Tool Configuration -> Git -> Git Installations -> Path to Git executable。

I was getting the same thing while connection to git from jenkins.从 jenkins 连接到 git 时,我得到了同样的东西。 Here is few checklist you would like to watch on :-这里有一些你想看的清单:-

Jenkins Configuration :-詹金斯配置:-
1) Check whether git executable is appropriately specified 1) 检查是否正确指定了 git 可执行文件
2) Provide SSH repository link git@blahblah 2)提供SSH仓库链接git@blahblah
3) Under credentials >> Select Username and Authentication key (go to your server, Generate SSH keys ssh-keygen... Copy keys to JENKINS_HOME/,ssh) 3) 在凭据下 >> 选择用户名和身份验证密钥(转到您的服务器,生成 SSH 密钥 ssh-keygen... 将密钥复制到 JENKINS_HOME/,ssh)
You should be able to connect to your GIT repository from Jenkins您应该能够从 Jenkins 连接到您的 GIT 存储库

You should install the Github Plugin for Jenkins.您应该为 Jenkins 安装Github 插件

After installation, in "Configure" within the project, there should be an input field for "GitHub project".安装后,在项目中的“配置”中,应该有一个“GitHub项目”的输入字段。 Input "https://github.com/micdoodle8/Crossbow_Mod_2" (without the quotes) there.在那里输入“https://github.com/micdoodle8/Crossbow_Mod_2”(不带引号)。 Additionally you put the same in the input field which says "Repositories" (the one you mentioned in your question) beneath it.此外,您将相同的内容放在输入字段中,该字段下方显示“存储库”(您在问题中提到的那个)。

您可能需要在 Manage Jenkins -> global tool configuration -> Git -> Git Installations -> Path to Git executable 中设置 git 可执行文件的路径。

You have to set your path to your Git executable which is in Global Tool Configuration of Manage Jenkins .您必须设置您的Git 可执行文件的路径,该文件位于Manage Jenkins 的全局工具配置中。 We can find location of a path via window power-shell as: Get-Command git.exe |我们可以通过window power-shell找到路径的位置: Get-Command git.exe | Select Definition shown in pcture as: command for git executable path选择pcture 中显示的定义为: git 可执行路径的命令

The problem may occur when your system can not locate git installation.当您的系统找不到git安装时可能会出现此问题。 If you are using Jenkins on VM or local system, locate the git installation folder.如果您在 VM 或本地系统上使用 Jenkins,请找到 git 安装文件夹。 For me (CentOS machine on AWS) it was in对我来说(AWS 上的 CentOS 机器)它在

/usr/bin/git

Put this path in Jenkins in Manage Jenkins -> Configure System -> Git -> Git Installations -> Path to Git executable将此路径放在 Jenkins 中的Manage Jenkins -> Configure System -> Git -> Git Installations -> Path to Git executable

https://i.stack.imgur.com/hSZ9N.png https://i.stack.imgur.com/hSZ9N.png

First of all git should be properly installed in your system.首先,git 应该正确安装在您的系统中。

Check if after installing git, path is given in system environment variables.检查安装git后,路径是否在系统环境变量中给出。 Add below paths in system variables "path" after installing git C:\\Apps\\Git\\bin C:\\Apps\\Git\\cmd安装 git C:\\Apps\\Git\\bin C:\\Apps\\Git\\cmd 后在系统变量“path”中添加以下路径

to test - run $ git -v in cmd prompt测试 - 在 cmd 提示符下运行 $ git -v

Next, go to Manage Jenkins -> global tool configuration -> Git -> Git Installations -> Path to Git executable -> enter path like C:\\Apps\\Git\\bin\\git.exe (wherever your git is installed)接下来,转到管理 Jenkins -> 全局工具配置 -> Git -> Git 安装 -> Git 可执行文件的路径 -> 输入类似 C:\\Apps\\Git\\bin\\git.exe 的路径(无论你的 git 安装在哪里)

For detailed description on this issues and git setup in Jenkins, you can check this blog post - https://thewebspark.com/2020/07/24/git-and-github-setup-in-jenkins/有关此问题的详细说明和 Jenkins 中的 git 设置,您可以查看此博客文章 - https://thewebspark.com/2020/07/24/git-and-github-setup-in-jenkins/

As described above by others, make sure that your Path to Git executable is right.如上所述,请确保您的 Git 可执行文件路径是正确的。 Be careful though how you find it: git --exec-path might give you a wrong path, eg mine is C:/Program Files/Git/mingw64/libexec/git-core.小心你如何找到它: git --exec-path可能会给你一个错误的路径,例如我的是 C:/Program Files/Git/mingw64/libexec/git-core。 Now, there IS a git.exe living there but this path in Path to Git executable seemed to be wrong.现在,有一个 git.exe 存在于那里,但是 Path to Git executable 中的这条路径似乎是错误的。 What you need is (sticking to my example above) C:\\Program Files\\Git\\bin\\git.exe你需要的是(坚持我上面的例子)C:\\Program Files\\Git\\bin\\git.exe

For Window it worked when I gave the complete path under the Global Tool Configuration:对于 Window,当我在全局工具配置下提供完整路径时,它起作用了:

C:\\Program Files\\Git\\bin\\git.exe C:\\Program Files\\Git\\bin\\git.exe

often times what happened to me was the directory was changed but the link for web hook still has the old directory.很多时候发生在我身上的事情是目录被更改了,但网络钩子的链接仍然是旧目录。 Maybe check that?也许检查一下?

This error can be resolved, if we change the path of Git on Global Configuration Tools page.如果我们在全局配置工具页面上更改 Git 的路径,则可以解决此错误。

Use Path- C:\Program Files\Git\bin\git.exe使用路径- C:\Program Files\Git\bin\git.exe

For Detailed steps refer Click here详细步骤参考点击这里

Hmmm....if you have jenkins running in a VM, make sure you install the package 'git-core' or 'git':嗯....如果你有 jenkins 在 VM 中运行,请确保安装包“git-core”或“git”:

sudo yum install git

After all, we must have git installed in the machine where jenkins is running.毕竟,我们必须在运行 jenkins 的机器上安装 git。 Otherwise you won't be able to run git commands.否则你将无法运行 git 命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM