Jenkins 和 Git 配置问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26647165/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:37:27  来源:igfitidea点击:

Jenkins and Git configuration issue

gitjenkinsjenkins-plugins

提问by senchaDev

I have been using Git for sometime now.

我已经使用 Git 有一段时间了。

Recently, I have started exploring Jenkins and I managed to set it up using the native windows installer. I created a sample project on my local system and built it using Jenkins successfully.

最近,我开始探索 Jenkins,并设法使用本机 Windows 安装程序进行设置。我在本地系统上创建了一个示例项目,并成功地使用 Jenkins 构建了它。

Now, I have a project on remote Server and I want Jenkins to pull this code using Git.

现在,我在远程服务器上有一个项目,我希望 Jenkins 使用 Git 提取此代码。

I did the following:

我做了以下事情:

1) Installed the Git Plugin.enter image description here

1) 安装了 Git 插件。在此处输入图片说明

2) In Jenkins > Manage Jenkins > Configure System > Git > Git installations -

2) 在 Jenkins > 管理 Jenkins > 配置系统 > Git > Git 安装 -

enter image description here

在此处输入图片说明

[also tried C:\Program Files (x86)\Git\cmd\gitk.cmd instead of ....\git.exe]

[也试过 C:\Program Files (x86)\Git\cmd\gitk.cmd 而不是 ....\git.exe]

3) Under the Test project > Configure enter image description here

3)在测试项目>配置下 在此处输入图片说明

4) Finally, tried to build it. But always get timeout error and then failure. enter image description here

4)最后,尝试构建它。但总是得到超时错误然后失败。 在此处输入图片说明

Started by user anonymous
Building in workspace C:\Program Files (x86)\Jenkins\workspace\GitTest
 > C:\Program Files (x86)\Git\cmd\git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > C:\Program Files (x86)\Git\cmd\git.exe config remote.origin.url ssh://git@<the-url-to-the-server>demo_android.git # timeout=10
Fetching upstream changes from ssh://git@<the-url-to-the-server>demo_android.git
 > C:\Program Files (x86)\Git\cmd\git.exe --version # timeout=10
 > C:\Program Files (x86)\Git\cmd\git.exe fetch --tags --progress ssh://git@<the-url-to-the-server>demo_android.git +refs/heads/*:refs/remotes/origin/* # timeout=60
FATAL: Failed to fetch from ssh://git@<the-url-to-the-server>demo_android.git
hudson.plugins.git.GitException: Failed to fetch from ssh://git@<the-url-to-the-server>demo_android.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:647)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:889)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:914)
    at hudson.model.AbstractProject.checkout(AbstractProject.java:1258)
    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:622)
    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:86)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:528)
    at hudson.model.Run.execute(Run.java:1759)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:89)
    at hudson.model.Executor.run(Executor.java:240)
Caused by: hudson.plugins.git.GitException: Command "C:\Program Files (x86)\Git\cmd\git.exe fetch --tags --progress ssh://git@<the-url-to-the-server>demo_android.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: ssh: connect to host git.us1.adeptra.com port 7999: Bad file number
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1435)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1223)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access0(CliGitAPIImpl.java:85)
    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.execute(CliGitAPIImpl.java:280)
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:645)
    ... 10 more

What am I doing wrong? Do i need to provide credentials? (I tried that it failed too)

我究竟做错了什么?我需要提供凭据吗?(我试过它也失败了)

采纳答案by senchaDev

Solved it ! The SSH key had a passphrase. I removed it and it worked fine.

解决了!SSH 密钥有一个密码短语。我删除了它,它运行良好。

Removed the passphrase by following the instructions in the link -

按照链接中的说明删除了密码短语 -

http://www.thinkplexx.com/learn/howto/security/ssl/remove-passphrase-password-from-private-rsa-key

http://www.thinkplexx.com/learn/howto/security/ssl/remove-passphrase-password-from-private-rsa-key

回答by Highmastdon

You need to provide authentication. Either do that by using plain text and fill it in the config or the command-line, or use a certificatessh-public-key to do that.

您需要提供身份验证。要么使用纯文本并在配置或命令行中填写它,要么使用证书ssh-public-key 来做到这一点。

Here you can find a tutorialon how to connect it to GitHub, and I think it should be done likewise on you own git-server.

在这里你可以找到一个关于如何将它连接到 GitHub的教程,我认为它应该在你自己的git-server 上完成