0

We would like to connect TFS2017 to out GitHub for Enterprise.

  • Added a new Service endpoint to "External Git"
  • Configured it using my ghe username and a personal access token
  • Added a new build definition
  • Selected external git, and the service just configured
  • Entered name of repository (no dropdown, tried various formats including the full https://ghe.mycompany.com/myUsername/myTestRepository.git)
  • Triggered a new build

We get an error when we try to clone. The error occurs in "Get sources" step (1_Get_sources.txt)

2016-11-21T13:31:20.4836373Z Syncing repository: https://ghe.mycompany.com/********/myTestRepository.git (Git)
2016-11-21T13:31:20.5326404Z Starting clone
2016-11-21T13:31:21.0286690Z ##[error]LibGit2Sharp.LibGit2SharpException: Request failed with status code: 404
2016-11-21T13:31:21.0296729Z ##[error]   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
2016-11-21T13:31:21.0306726Z ##[error]   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)
2016-11-21T13:31:21.0316723Z ##[error]   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)
2016-11-21T13:31:21.0336678Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.CloneRepository(String repositoryPath, Uri repositoryUrl, Boolean checkoutSubmodules, String username, String password)
2016-11-21T13:31:21.0346735Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(Uri repositoryUrl, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion, String username, String password)
2016-11-21T13:31:21.0356736Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(ITaskEndpoint endpoint, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion)
2016-11-21T13:31:21.0366732Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(Boolean cleanRepository, String sourceBranch, String sourceVersion, Boolean checkoutSubmodules, CancellationToken cancellationToken)
2016-11-21T13:31:21.0376729Z ##[error]   at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()

Localy (on the TFS server) we're able to clone using powershell, and executing a script in a build step let us verify that the same proxy settings are used.

Below are some more debug from the _diag folder

    11:35:23.072987 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = Syncing repository: https://ghe.mycompany.com/********/myTestRepository.git (Git))
11:35:23.076124 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = repository url=https://ghe.mycompany.com/api/v3)
11:35:23.078235 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = checkoutSubmodules=False)
11:35:23.087627 Syncing and checking out sources.
11:35:23.087627 rootPath=C:\TfsBuildAgents\Agent-smi-build01\_work\22\s
11:35:23.087627 cleanRepository=True
11:35:23.087627 sourceBranch=master
11:35:23.087627 sourceVersion=
11:35:23.088628 sourcesToBuild=refs/remotes/origin/master
11:35:23.092875 Checking if the repo on disk matches the expected repository URL.
11:35:23.092875 gitRepoFolder=C:\TfsBuildAgents\Agent-smi-build01\_work\22\s
11:35:23.092875 expectedRepositoryUrl=https://ghe.mycompany.com/api/v3
11:35:23.120701 Unable to determine whether the existing repo matches. Suppressing the exception and treating the repo as if it doesn't match. For verbose purposes only, the exception is: LibGit2Sharp.RepositoryNotFoundException: Path 'C:\TfsBuildAgents\Agent-smi-build01\_work\22\s' doesn't point at a valid Git repository or workdir.
   at LibGit2Sharp.Core.Proxy.git_repository_open(String path)
   at LibGit2Sharp.Repository..ctor(String path, RepositoryOptions options, RepositoryRequiredParameter requiredParameter)
   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.IsExpectedRepository(String gitRepoFolder, Uri expectedRepositoryUrl)
11:35:23.127765 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = Starting clone)
11:35:23.133909 Process logging event with task handler.
11:35:23.613344 ---------------------------------------------------------------------------
11:35:23.615482 LibGit2Sharp.LibGit2SharpException: Request failed with status code: 404

11:35:23.615482    at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)

11:35:23.615482    at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)

11:35:23.615482    at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)

11:35:23.615482    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.CloneRepository(String repositoryPath, Uri repositoryUrl, Boolean checkoutSubmodules, String username, String password)

11:35:23.615482    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(Uri repositoryUrl, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion, String username, String password)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(ITaskEndpoint endpoint, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(Boolean cleanRepository, String sourceBranch, String sourceVersion, Boolean checkoutSubmodules, CancellationToken cancellationToken)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()
11:35:23.616553    at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)

11:35:23.616553    at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts)

11:35:23.616553    at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.CloneRepository(String repositoryPath, Uri repositoryUrl, Boolean checkoutSubmodules, String username, String password)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(Uri repositoryUrl, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion, String username, String password)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(ITaskEndpoint endpoint, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(Boolean cleanRepository, String sourceBranch, String sourceVersion, Boolean checkoutSubmodules, CancellationToken cancellationToken)

11:35:23.616553    at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0()
11:35:23.617555 ---------------------------------------------------------------------------
11:35:23.618654 Process logging event with task handler.
11:35:23.623821 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]LibGit2Sharp.LibGit2SharpException: Request failed with status code: 404)
11:35:23.624910 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result))
11:35:23.625909 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at LibGit2Sharp.Core.Proxy.git_clone(String url, String workdir, GitCloneOptions& opts))
11:35:23.626974 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at LibGit2Sharp.Repository.Clone(String sourceUrl, String workdirPath, CloneOptions options))
11:35:23.627973 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.CloneRepository(String repositoryPath, Uri repositoryUrl, Boolean checkoutSubmodules, String username, String password))
11:35:23.629042 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(Uri repositoryUrl, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion, String username, String password))
11:35:23.630112 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncRepository(ITaskEndpoint endpoint, String rootPath, Boolean cleanRepository, Boolean checkoutSubmodules, String sourceVersion))
11:35:23.631180 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.Core.GitHelper.SyncAndCheckout(Boolean cleanRepository, String sourceBranch, String sourceVersion, Boolean checkoutSubmodules, CancellationToken cancellationToken))
11:35:23.632188 BaseLogger.LogConsoleMessage(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, message = ##[error]   at Microsoft.TeamFoundation.DistributedTask.Plugin.Build.GitSourceProvider.<>c__DisplayClass3_0.<PrepareRepositoryAsync>b__0())
11:35:23.634183 Process logging event with task handler.
11:35:23.638350 BaseLogger.LogStatus(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, scope.TimelineRecordId = 2fd7ca75-f01d-4906-bf39-7c8d66a1df7f, record.Name = )
11:35:23.649716 BaseLogger.LogAttachment(scope.JobId = af970025-e4bc-4692-a708-bbe734745370, type = DistributedTask.Core.Log, name = Get sources, path = C:\TfsBuildAgents\Agent-smi-build01\_diag\w7ac045c8-3285-4be2-b993-b542da560c11.log)
11:35:23.658368 ---------------------------------------------------------------------------
11:35:23.660442 System.AggregateException: One or more errors occurred. ---> Microsoft.TeamFoundation.DistributedTask.Agent.Common.AgentExecutionTerminationException: Prepare repository failed with exception. ---> LibGit2Sharp.LibGit2SharpException: Request failed with status code: 404

Any idea how to debug this, or what we might try?

Larsi
  • 4,654
  • 7
  • 46
  • 75
  • According to the error info it's something more like the url error? Did you have any proxy of your network? – PatrickLu-MSFT Nov 24 '16 at 10:08
  • @Patrick-MSFT Thanks for looking into this. When we do a git config --get http.proxy in powershell on the TFS server, and when we add a custom script to the build that prints out the proxy, they are both set to the same (correct value) - Maybe TFS git proxy is configured somewhere else? – Larsi Nov 24 '16 at 14:28
  • You mentioned that "the same proxy settings are used (none)". Do you mean you didn't use any proxy or the http.proxy you get is "none"? – Eddie Chen - MSFT Nov 25 '16 at 02:29
  • @Patrick-MSFT sorry, error in the question. There is a proxy, and based on the git config commands, it looks like it set correctly. I'll update my question. – Larsi Nov 25 '16 at 08:01
  • When you check the git config on the build server are you checking it with the account you're running the build agent under? – DaveShaw Nov 25 '16 at 08:17
  • Yes. I even switched the TFS to run under my account – Larsi Nov 25 '16 at 08:54
  • Can you set your build agent to run behind a proxy via this link: https://www.visualstudio.com/en-us/docs/build/admin/agents/v2-windows#run-the-agent-behind-a-web-proxy and then try again? – Eddie Chen - MSFT Nov 28 '16 at 00:57
  • @Eddie-MSFT Thanks for looking into this. Added proxy file in root dir, and restarted agent service, no change, got the same 404. Are there other logs I could provide? – Larsi Nov 28 '16 at 09:54
  • Looks like you're using the 1.x agent, try installing the new 2.x agent, it uses git.exe to communicate to the external server, likely that fixes your problem. – jessehouwing Dec 18 '16 at 18:38

1 Answers1

1

According to this page you can't connect to Github Enterprise using TFS 2017. Please let me know if this has changed as I'd love to be able to do this!

Ben_G
  • 770
  • 2
  • 8
  • 30