Search code examples
gitjenkinstfstfs-2015

cannot connect to TFS 2015 git repository from Jenkins


I cannot connect to my TFS 2015 git repository from Jenkins. I keep getting the following error:

Failed to connect to repository : Command "C:\Program Files\Git\bin\git.exe ls-remote -h -- https://tfsservername/tfs/DefaultCollection/_git/reponame.git HEAD" returned status code 128:
stdout:
stderr: Logon failed, use ctrl+c to cancel basic credential prompt.
fatal: Authentication failed for 'https://tfsservername/tfs/DefaultCollection/_git/reponame.git/'

My configuration:

  • Jenkins 2.204.5
  • TFS 2015 Update 3
  • Jenkins Git plugin 4.2.2
  • Jenkins Git client plugin 3.2.1

I have tried different combinations of credentials. For username I've done domain\username, username@domain, just username and for password I've used a personal access token and the TFS site password. Every combination I've tried comes back with 'Authentication failed'. Does anyone have any suggestions?

UPDATE: Here's some more background. I'm trying to connect to an external TFS server from my Windows computer. The server is a work server and I don't have control over it. I added the port number to the git repo url and got a different error message. This is what I got:

Failed to connect to repository : Command "C:\Program Files\Git\bin\git.exe ls-remote -h -- https://tfsservername:8080/tfs/DefaultCollection/_git/portal HEAD" 
returned status code 128: stdout:stderr: fatal: unable to access 'https://tfsservername:8080/tfs/DefaultCollection/_git/portal/': schannel: 
next InitializeSecurityContext failed: SEC_E_INVALID_TOKEN (0x80090308) 
The token supplied to the function is invalid

I had a similar problem when downloading custom NuGet packages from this TFS server. I was able to solve the problem before by add credentials to a NuGet.config file. The credentials I used were username and a PAT and added a value of 'basic' for ValidAuthenticationTypes. That worked. In Jenkins using the same type of credentials doesn't work.


Solution

  • A co-worker helped me figured it out. It was a DNS issue. I have to use a VPN to connect to the TFS server because it's private work server. I had to go to Control Panel->Network Connections->vEthernet Properties->Internet Protocol Version 4/TCP/IPv4 Properties, then to Advanced TCP/IP settings. I selected 'Append these DNS suffixes..' and added the suffixes associated with my TFS server. Then in Jenkins I used my TFS username and password for credentials. No error messages. @PatrickLu-MSFT When you mentioned it could be a network issue it got me thinking. Thanks for your help.