Connecting TeamCity to TFS [duplicate]

2019-01-15 10:11发布

问题:

This question already has an answer here:

  • Connect TeamCity to Visual Studio Online 3 answers

I'm struggling trying to connect my TeamCity project to my TFS project. I tried a bunch of stuff, but I always get the same error:

TFS failed. ExitCode: 111, command: C:\TeamCity\webapps\ROOT\WEB-INF\plugins\tfs\bin\tfs-native.exe @@C:\TeamCity\temp\TC-TFS-25-7939_109\command.params, in file: {https://budiedimas.visualstudio.com/DefaultCollection/TesteTeamCity, /hash:S, /noProxy, C:\TeamCity\temp\TC-TFS-25-7939_108.result, ConnectionTest, $/TesteTeamCity/TesteTeamCity}, completed in: 1 second(s)
stdout: TFS Native Verifier v8.0 Copyright (C) 2006-2013 JetBrains s.r.o.
Running under .NET Framework 4.0.30319.18052
INFO  - 
INFO  - Use Team Explorer 2012
INFO  - 
TFS Native Accessor v8.0 Copyright (C) 2006-2013 JetBrains s.r.o.
INFO  - Connecting to server https://budiedimas.visualstudio.com/DefaultCollection/TesteTeamCity
INFO  - WebProxy is disabled
Connection test:
  Server='https://budiedimas.visualstudio.com/DefaultCollection/TesteTeamCity'
  Root='$/TesteTeamCity/TesteTeamCity'
ERROR - TF30063: You are not authorized to access https://budiedimas.visualstudio.com/DefaultCollection/TesteTeamCity.
System.Exception: TF30063: You are not authorized to access https://budiedimas.visualstudio.com/DefaultCollection/TesteTeamCity. ---> Microsoft.TeamFoundation.TeamFoundationServerUnauthorizedException: TF30063: You are not authorized to access https://budiedimas.visualstudio.com/DefaultCollection/TesteTeamCity.
   em Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.EnsureTokenProvider(HttpWebResponse webResponse)
   em Microsoft.TeamFoundation.Client.Channels.TfsHttpWebRequest.SendRequest()
   em Microsoft.TeamFoundation.Client.Channels.TfsHttpRequestChannel.Request(TfsMessage message, TimeSpan timeout)
   em Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)
   em Microsoft.TeamFoundation.Framework.Client.Registration.GetRegistrationEntries(String toolId)
   em Microsoft.TeamFoundation.Framework.Client.RegistrationProxy.GetRegistrationEntries(String toolId)
   em Microsoft.TeamFoundation.Framework.Client.RegistrationService.GetInstanceId()
   em Microsoft.TeamFoundation.Framework.Client.RegistrationService.get_InstanceClientCacheDirectory()
   em Microsoft.TeamFoundation.Framework.Client.RegistrationService..ctor(TfsTeamProjectCollection tfsObject)
   em Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.CreateServiceProxy(Type serviceType)
   em Microsoft.TeamFoundation.Client.TfsTeamProjectCollection.GetServiceInstance(Type serviceType, Object serviceInstance)
   em Microsoft.TeamFoundation.Client.TfsConnection.GetService(Type serviceType)
   em Microsoft.TeamFoundation.Framework.Client.PreFrameworkServerDataProvider.FindServiceLocation(String serviceType, String toolId)
   em Microsoft.TeamFoundation.Framework.Client.PreFrameworkServerDataProvider.LocationForCurrentConnection(String serviceType, Guid serviceIdentifier)
   em Microsoft.TeamFoundation.Client.TfsConnection.EnsureProviderConnected()
   em JetBrains.TeamCity.Tfs.Command.Do() na c:\BuildAgent\work\23f504c63c17dfdf\TfsNativeAccessor\src\Command.cs:linha 28
   em JetBrains.TeamCity.Tfs.Program.Main(String[] args) na c:\BuildAgent\work\23f504c63c17dfdf\TfsNativeAccessor\src\Program.cs:linha 134
   --- Fim do rastreamento de pilha de exce‡äes internas ---
   em JetBrains.TeamCity.Tfs.Program.Main(String[] args) na c:\BuildAgent\work\23f504c63c17dfdf\TfsNativeAccessor\src\Program.cs:linha 438

I always get the error:

'You are not authorized to access /DefaultCollection/'

I have admin rights in everything on the TFS and I don't know if I'm missing some authorizantion configuration on the TeamCity.

Does anyone have any idea why this is happening?

回答1:

I finally managed to get this working in the latest version of teamcity (which for me is 8.0.3) but apparently this has been working since version 7.1.4.

  1. First configure alternate credentials in TFS (profile -> credentials -> enable alternate credentials)

  2. Then in TeamCity

    • Use the following URL format: https://{yournamehere}.visualstudio.com/DefaultCollection
    • For the username use the alternate credential name you setup in step 1. BUT put it in the following format "##LIVE##\usernamehere" (It actually tells you this below the box, but I somehow missed it first time!)

Hope this helps someone else, as I wasted quite a bit of time on this!



回答2:

I've blurred out my url name and username, but I know pictures help a lot of people. This is @Rob Birds solution to the problem. I can't thank him enough! Again, ensure you have at least VisualStudio 2012 Update 1 with Team Explorer installed on the TeamCity build server and agent. After updating Visual Studio (if needed), you'll need to restart the TeamCity build server and build agent as well.



回答3:

Looks like its a cache issue. Restarting the Team city service worked for me