git - Jenkins 不会连接到 TFS-GIT 存储库

标签 git tfs jenkins

我正在尝试将 Jenkins 作业从 SVN 更改为新的 TFS-GIT 存储库(托管在我们的组织内)。

我指定了 Git 存储库

http://thehost:8080/tfs/path/_git/reponame

Jenkins 告诉我

Failed to connect to repository : Failed to connect to http://thehost:8080/tfs/path/_git/reponame (status = 401)

我可以使用相同的 repo URL 从 linux 命令行成功运行 Git,并且它不会提示输入密码(使用 .git-credentials 中的值)。

配置是

Jenkins 服务器

  • Red Hat Enterprise Linux Server 6.3 版(圣地亚哥)
  • 英特尔至强 64 位 x15 x86_64
  • Jenkins 1.548
  • Git 1.8.5.5
  • Jenkins Git 插件 1.5.0
  • Jenkins GIT 客户端插件 1.7.0

TFS-GIT 服务器

  • Microsoft Visual Studio Team Foundation Server 版本 12.0.21005.1

在作业控制台中有同样的错误:

Building in workspace /var/lib/jenkins/workspace/myproject
Checkout:myproject / /var/lib/jenkins/workspace/myproject - hudson.remoting.LocalChannel@3edcc1f9
Using strategy: Default
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
hudson.plugins.git.GitException: Failed to connect to http://thehost:8080/tfs/path/_git/reponame (status = 401)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.checkCredentials(CliGitAPIImpl.java:1911)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1105)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1073)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1064)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.fetch(CliGitAPIImpl.java:286)
at hudson.plugins.git.GitAPI.fetch(GitAPI.java:235)
at hudson.plugins.git.GitAPI.fetch(GitAPI.java:239)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:791)
at hudson.plugins.git.GitSCM.access$000(GitSCM.java:58)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:983)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:948)
at hudson.FilePath.act(FilePath.java:914)
at hudson.FilePath.act(FilePath.java:887)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:948)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1114)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1411)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:560)
at hudson.model.Run.execute(Run.java:1670)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:519)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:231)
ERROR: Could not fetch from any repository
java.io.IOException: Could not fetch from any repository
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:992)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:948)
at hudson.FilePath.act(FilePath.java:914)
at hudson.FilePath.act(FilePath.java:887)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:948)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1114)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1411)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:651)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:560)
at hudson.model.Run.execute(Run.java:1670)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:519)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:231)

用户名的格式为域\用户名。

我已经尝试了一些方法但没有结果。

  • 将用户名和密码放在 URL 中
  • 将 Git 插件和 Git 客户端插件降级到各种版本(虽然可能没有得到正确的组合)
  • 降级和升级git

感谢您的建议。

更新:

我通过将 SCM 设置为“无”、使用“定期构建”而不是“轮询 SCM”并添加一个预构建步骤(执行 Shell)来检查来自 Git 的代码,从而使 Jenkins 构建工作:

rm -rf $WORKSPACE/* $WORKSPACE/.git
/usr/local/bin/git clone -b branch --single-branch http://DOMAIN\\username:xxxxx@thehost:8080/tfs/path/_git/reponame $WORKSPACE

我仍然非常欢迎任何允许我使用“Poll SCM”而不是定期构建的建议。看起来 Git 客户端可能只是不喜欢 DOMAIN\username -style names(?)

最佳答案

我在绞尽脑汁后找到了解决这个问题的方法……默认情况下,TFS 使用 NTLM 与 Git 理解的基本身份验证进行身份验证。解决此问题的方法是允许通过 TFS 进行基本身份验证。参见 http://almcrank.com/jenkins-build-with-a-git-repository-tfs/

一开始我没有运气,经过多次试验和错误后发现我需要在选择“基本身份验证”时额外单击 IIS 管理面板右侧的“编辑”,我不得不放入我的默认域。没有这个,它似乎没有正确理解反斜杠(即 DOMAIN\user)。然后在 Jenkins 中,确保您的凭证在没有域的情况下被传递。

enter image description here

另一件需要考虑的事情是 Git 没有本地方式来存储 HTTP 凭据。所以你有几个选择:

  • 使用凭据存储/git-credential-winstore/netrc - 阅读这篇文章了解更多信息:https://confluence.atlassian.com/display/STASH/Permanently+authenticating+with+Git+repositories .如果选择 netrc,我建议你 pgp 加密你的密码。
  • 将用户名和密码放入存储库 URL 并将凭据设置为“无”(即 http://USERNAME:PASSWORD@yourserver.com/tfs/_git/YOURREPO)。如果选择此选项,我建议您确保您的帐户只有必要的访问权限并且 TFS 服务器具有 SSL 证书并使用 HTTPS。

关于git - Jenkins 不会连接到 TFS-GIT 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22825871/

相关文章:

jenkins - 推送图像与构建系统本身,docker

git - 不能 "git bisect reset";无尽的 stash/重置循环

git - 将功能分支 rebase /复制到旧版本

visual-studio-2008 - 存在哪些其他 TFS 客户端?

tfs - 有没有一种简单的方法来获取文件并将最后一次 checkin 作为文件的时间戳?

git - 如何检测 "repo"的变化以在Jenkins中进行持续集成?

git - 如何使 HEAD 和 origin/master 指向相同(最新)修订版。 (HEAD 指向最新版本,而 origin/master 指向过去版本)

git - 远程拒绝推送,提交必须有有效签名

c# - 如何在我的项目中引用 TeamFoundation 程序集?

Jenkins 管道参数来保存一个数组