Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins won't connect to TFS-GIT repository

Tags:

git

jenkins

tfs

I'm trying to change over a Jenkins job from SVN to a new TFS-GIT repository (hosted within our organization).

I specified the Git repository

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

Jenkins tells me

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

I can run Git successfully from the linux command line with the same repo URL and it doesn't prompt for a password (values from .git-credentials are used).

The configuration is

Jenkins server

  • Red Hat Enterprise Linux Server release 6.3 (santiago)
  • intel xeon 64 bit x15 x86_64
  • Jenkins 1.548
  • Git 1.8.5.5
  • Jenkins Git Plugin 1.5.0
  • Jenkins GIT client plugin 1.7.0

TFS-GIT server

  • Microsoft Visual Studio Team Foundation Server Version 12.0.21005.1

In the job console there is just the same error:

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)

The username is in the format DOMAIN\username.

I've tried a few approaches already with no results.

  • putting the username and password in the URL
  • downgrading Git plugin and Git Client plugin to various versions (maybe didn't get the right combination, though)
  • downgrading and upgrading git

Thank you for your advice.

Update:

I got the Jenkins build working by setting SCM to "none", using "Build periodically" instead of "Poll SCM", and adding a pre-build step (Execute Shell) which checks out the code from Git:

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

I would still very much welcome any advice that would allow me to use "Poll SCM" instead of building periodically. It seems like maybe the Git Client just doesn't like the DOMAIN\username -style names(?)

like image 245
user3491575 Avatar asked Oct 21 '22 11:10

user3491575


1 Answers

I found out how to solve this issue after much racking my brain... by default TFS authenticates using NTLM vs. Basic auth which is what git understands. The way you fix this is through allowing Basic authentication through TFS. See http://almcrank.com/jenkins-build-with-a-git-repository-tfs/

I did this at first, without luck, and after much trial and error found that I needed to additionally click "Edit" on the right-hand side of the IIS admin panel while "Basic authentication" is selected and I had to put in my default domain. Without this, it seems as though it wasn't understanding the backslash appropriately (i.e DOMAIN\user). Then in Jenkins, ensure that your credential is being passed without the domain.

enter image description here

Another thing to consider is that Git has no native way to store HTTP credentials. So you're left with a few options:

  • Use the credential store/git-credential-winstore/netrc - read this article for more info: https://confluence.atlassian.com/display/STASH/Permanently+authenticating+with+Git+repositories. If netrc is chosen, I would suggest you pgp encrypt your password.
  • Put the username and password in the repository URL and set the credential to "None" (i.e. http:// USERNAME:[email protected]/tfs/_git/YOURREPO). If this option is chosen, I would suggest you ensure your account only has necessary access and the TFS server has a SSL certificate and utilize HTTPS.
like image 103
Josh Barker Avatar answered Oct 27 '22 18:10

Josh Barker