cannot connect to TFS 2015 git repository from Jenkins

0

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.

git
jenkins
tfs
tfs-2015
asked on Stack Overflow Mar 23, 2020 by mdailey77 • edited Mar 24, 2020 by mdailey77

3 Answers

1

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.

answered on Stack Overflow Mar 28, 2020 by mdailey77
0

The repo url you are using do not need to contain extra .git as a suffix.

Just as https://tfsservername/tfs/DefaultCollection/_git/reponame

Besides, you could also try to combine authentication with the repo url kind like:

For this kind of Authentication failed error, if you are using PAT token to handle the authentication with on-premise TFS server, make sure you already turned off Basic Authentication on server. Otherwise you will get an returned error.

We recommend you keep IIS Basic Authentication turned off at all times when using Azure DevOps Server. Only if necessary should you enable IIS Basic Authentication. When IIS Basic Authentication is enabled on your windows machine, it prevents you from using personal access tokens (PATs) as an authentication mechanism.

Source link

And for clone url in TFS, should be kind like below:

git clone https://PAT@tfsservername:8080/tfs/Collectionname/Projectname/_git/GitReponame

If all above still not work, check you are behind a proxy or not. Try to temporarily turn off the proxy.

Other ways may help to narrow down if the issue is related to TFS side or network. You could directly access those URL from the browser, double check if you have any trouble.

answered on Stack Overflow Mar 24, 2020 by PatrickLu-MSFT
0

If your build server is a windows machine, Git for Windows uses the windows uses the Windows Credential Manager to store credentials. Login as the build agent account and make sure you add an entry in the Credential manager for your TFS server like this Windows Credential Manager

Then you can run this git command to make sure it will use the credential manager

git config --global credential.helper manager
answered on Stack Overflow Mar 24, 2020 by Etienne

User contributions licensed under CC BY-SA 3.0