Azure DevOps - Git integration

Hello all,

I am trying to configure git TwoWay sync between my universal instance and a local azure devops server. I was following the tutorial found here: PowerShell Universal: Git Synchronization - YouTube and keep receiving the following error:

2021-06-24T16:02:02.5819175-05:00  [ERR] Failed to sync: "too many redirects or authentication replays" "   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)

Any help would be greatly appreciated :slight_smile:

appsettings.json:

"Data": {
    "RepositoryPath": "%ProgramData%\\UniversalAutomation\\Repository",
    "ConnectionString": "%ProgramData%\\UniversalAutomation\\database.db",
    "GitRemote": "http://localazuredevops/_git/PowershellUniversal",
    "GitUserName": "myusername",
    "GitPassword": "personalaccesstoken", 
    "GitBranch": "master",
    "GitSyncBehavior": "TwoWay",
    "ConfigurationScript": ""
  },

Full log

2021-06-24T16:02:02.5819175-05:00  [ERR] Failed to sync: "too many redirects or authentication replays" "   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote, IEnumerable`1 refSpecs, GitFetchOptions fetchOptions, String logMessage)
   at LibGit2Sharp.Commands.Fetch(Repository repository, String remote, IEnumerable`1 refspecs, FetchOptions options, String logMessage)
   at LibGit2Sharp.Commands.Pull(Repository repository, Signature merger, PullOptions options)
   at UniversalAutomation.Git.GitService.Pull() in D:\a\universal\universal\src\UniversalAutomation.Git\GitService.cs:line 235
   at UniversalAutomation.GitSyncService.TrySync() in D:\a\universal\universal\src\UniversalAutomation\Services\GitSyncService.cs:line 84
   at UniversalAutomation.GitSyncService.Sync() in D:\a\universal\universal\src\UniversalAutomation\Services\GitSyncService.cs:line 55" (2d6ed692) 
Product: PowerShell Universal
Version: 1.5.14

If you are using DevOps 2019 (TFS) or later, you could create a pipeline to push/deploy changes using MSDeploy batch script (if remote/network) or ssh/scp and have the pipeline with trigger even enabled.

This helps in automating deployments when using TFS environment.

I’d try updating to at least 1.5.15. This update fixed a git syncing issue and may fix the issue you see here.

In my environment I use Azure DevOps and Git Sync with master and develop branches and everything runs smoothly. Currently on 2.0.3.

Good point. I tried on the latest build of 2.0.3 on a test machine and got the same result.

2021-06-25T09:43:02.0310395-05:00  [INF] Finished groom job. (ccb4f234)
2021-06-25T09:43:03.1271488-05:00  [ERR] Failed to sync: "too many redirects or authentication replays" "   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteHandle remote, IEnumerable`1 refSpecs, GitFetchOptions fetchOptions, String logMessage)
   at LibGit2Sharp.Commands.Fetch(Repository repository, String remote, IEnumerable`1 refspecs, FetchOptions options, String logMessage)
   at LibGit2Sharp.Commands.Pull(Repository repository, Signature merger, PullOptions options)
   at UniversalAutomation.Git.GitService.Pull() in D:\a\universal\universal\src\UniversalAutomation.Git\GitService.cs:line 236
   at UniversalAutomation.GitSyncService.TrySync() in D:\a\universal\universal\src\UniversalAutomation\Services\GitSyncService.cs:line 90
   at UniversalAutomation.GitSyncService.Sync() in D:\a\universal\universal\src\UniversalAutomation\Services\GitSyncService.cs:line 60" (2d6ed692)

I made a mistake. This is azure devops instance. :slight_smile:

Interesting - I’m also on 2.0.3 and have two-way sync with Azure Devops working - only difference in config near as I can tell is I don’t have anything specified in the GitBranch field.

Also note I gave the personal access taken in devOps full access.

With the following config settings

"Data": {
    "RepositoryPath": "%ProgramData%\\UniversalAutomation\\Repository",
    "ConnectionString": "filename=%ProgramData%\\UniversalAutomation\\database.db;upgrade=true",
    "GitRemote": "{redacted}/PowershellUniversal",
    "GitUserName": "someuser",
    "GitPassword": "PersonalAccessToken", 
    "GitBranch": "",
    "GitSyncBehavior": "TwoWay",
    "ConfigurationScript": ""
  },

Still receiving the following error:

[ERR] Failed to sync: "too many redirects or authentication replays" "   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)

Interesting - my token only has Read+Write to Code.

Any chance your tenant has some of those new policies?
New policies for personal access tokens | Microsoft Docs

Here’s my configuration which works. I don’t see anything obviously wrong with yours.

{
    "RepositoryPath": "%ProgramData%\\UniversalAutomation\\Repository",
    "ConnectionString": "filename=%ProgramData%\\UniversalAutomation\\database.db;upgrade=true",
    "GitRemote": "https://myorg@dev.azure.com/myorg/mydevopsproject/_git/reponame",
    "GitUserName": "any",
    "GitPassword": "mypersonalaccesstoken",
    "GitBranch": "develop",
    "GitSyncBehavior": "TwoWay",
    "ConfigurationScript": ""
  }

I would check your local git configuration. Go to %ProgramData%\UniversalAutomation\Repository and try opening up a git terminal. If you can’t pull/push/commit then something is misconfigured with your local git configurations - probably a permissions issue.

Update:

I was able to get it to work on github and through dev.azure.com by wiping my .git folder and restarting IIS. Still getting the same redirect error message with out internally hosted devops.

Working with a few others to see if there is something internally that could be causing it to fail.

Would it matter if its talking over port http internally? Seems like that is the only difference I can tell.

I may have observed a related issue - My DevOps repo had stopped getting commits from Universal in the last few weeks.

I opened Git GUI in my Repository folder and got a message about loose objects and a suggestion to compress the database. I let it compress, and git sync is working again.

1 Like

Seem to be getting this myself now.

Everything’s been working perfectly syncing to my app service deployment up until a colleague and I started doing some updates tonight - somewhere after an hour of successful pushes and pulls it stopped working and I’ve tried every trick in the book so far to get it back with no luck.

  • Deleted the app service and redeployed everything - bizarrely it managed to still have the source code from the last successful pull - sync still broken
  • Git GUI also showed me the loose objects message - tried compressing - didn’t seem to make much difference
  • Deleted my source code repo and manually recreated it in case it was something in the history/branching that broke it - no improvement.

Currently waiting for it to redeploy after taking an axe to the app service plan as well as the app service - wondering if only deleting the app service left the disks in place and that’s why the source was still there with, I’m assuming whatever is broken in .git still there too.

Destroying everything didn’t help. Fixed it in the end by getting UD to initialize a completely new repo then carefully moving files across.

Having not worked out what was really causing the problem, I’m entirely paranoid about when/why it might happen again.

I had another customer experience this issue with GitHub Enterprise and had to regenerate their PAT to get it to sync properly. The Too Many Redirects were coming from it attempting to do some sort of auth flow.

Are you using the same PAT with the new repo?

1 Like

Annoyingly, I rolled the PAT at the same time I ditched the old repo - I tested the old PAT locally though and it was working ok.

If it happens again, I’ll roll the PAT before going nuclear on the repo and report back.

1 Like