我正在尝试将Jenkins的工作从SVN转换到新的TFS-GIT存储库(在我们的组织内托管).
我指定了Git存储库
http://thehost:8080/tfs/path/_git/reponame
Run Code Online (Sandbox Code Playgroud)
詹金斯告诉我
Failed to connect to repository : Failed to connect to http://thehost:8080/tfs/path/_git/reponame (status = 401)
Run Code Online (Sandbox Code Playgroud)
我可以使用相同的repo URL从linux命令行成功运行Git,并且不会提示输入密码(使用来自.git-credentials的值).
配置是
詹金斯服务器
TFS-GIT服务器
在作业控制台中,存在同样的错误:
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)
Run Code Online (Sandbox Code Playgroud)
用户名的格式为DOMAIN\username.
我已经尝试了一些没有结果的方法.
感谢您的意见.
更新:
我通过将SCM设置为"none",使用"Build periodic"而不是"Poll SCM",并添加一个预构建步骤(Execute 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
Run Code Online (Sandbox Code Playgroud)
我仍然非常欢迎任何允许我使用"民意调查SCM"而不是定期建立的建议.似乎Git Client可能不喜欢DOMAIN\username-style名称(?)
经过一番绞尽脑汁后,我发现了如何解决这个问题......默认情况下,TFS 使用 NTLM 进行身份验证,而基本身份验证是 git 所理解的。解决此问题的方法是通过 TFS 允许基本身份验证。请参阅http://almcrank.com/jenkins-build-with-a-git-repository-tfs/
我一开始就这么做了,但运气不好,经过多次尝试和错误后发现,在选择“基本身份验证”时,我还需要单击 IIS 管理面板右侧的“编辑”,并且必须输入我的默认域。如果没有这个,它似乎无法正确理解反斜杠(即 DOMAIN\user)。然后在 Jenkins 中,确保您的凭证在没有域的情况下传递。

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