我正在尝试使用 GIT 插件 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 存储库设置了 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: 标准输出: stderr: fatal: 'git@example.git' 似乎不是 git 存储库 fatal: 远端意外挂断
你必须做一些更多的配置:
1.转到终端
2.运行此命令:sudo visudo
3.在定义了 sudo previlage 的文件中添加 %jenkins ALL=NOPASSWD: ALL 并关闭文件。
4.通过命令以 jenkins 用户身份登录:sudo su jenkins
5.在jenkins主目录下创建.ssh目录
6.像这样创建公私钥对。
生成 SSH key :
1:检查 SSH key
首先,我们需要检查您计算机上现有的 ssh key 。打开终端并运行:
cd ~/.ssh 检查您的用户目录中是否有名为“.ssh”的目录
如果它说“没有这样的文件或目录”,请转到第 2 步。否则,您已经有一个现有的 key 对,您可以跳到第 3 步。
2:生成新的SSH key
要生成新的 SSH key ,请输入以下代码。我们需要默认设置,所以当要求输入一个文件来保存 key 时,只需按回车键。
ssh-keygen -t rsa -C "your_email@example.com"
创建一个新的 ssh key ,使用提供的电子邮件作为标签生成公共(public)/私有(private) rsa key 对。输入保存 key 的文件(/home/you/.ssh/id_rsa): 现在您需要输入密码或文件。按回车键,不要输入任何内容。
应该给你这样的东西:
您的身份已保存在 /home/you/.ssh/id_rsa 中。
您的公钥已保存在/home/you/.ssh/id_rsa.pub。 key 指纹为:
01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
3:将您的 SSH key 添加到 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 创建构建,打开控制台检查状态。
关于git - 为什么 Jenkins 中的 GIT 插件无法连接到 GIT 存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41741762/