1

I have a Gitlab CI pipeline that's building a Unity project which has packages being pulled from a git repository. There are a number of packages, but they're all in one of two groups, and I can get a PAT for both (I can't use SSH keys in this particular instance due to some other constraints). Unity uses the git credential manager to authenticate for packages (details), but I'm unsure how to actually add those credentials to the helper from the command line.

The runner is using the Shell executor on a Windows 10 machine, and I can inject the PATs using environment variables, but the part I don't know how to do is get them added to the credential manager, and in this case they will need to be scoped to the specific group URLs similar to this answer. The git installation on this machine is also configured to use the Windows Credential Manager.

1 Answers1

2

how to do is get them added to the credential manager

In command line

printf "host=remote.host.name\nprotocol=https\nusername=aUser\npasswprd=<yourPAT>" | \
git credential-manager-core store

(As commented by the OP Alex McCraw, that requires installing the latest Git for Windows, 2.35.1.2, at the time of writing, Q1 2022)

This assume that, when executed on a Windows 10 machine:

  • git config credential.helper returns credential-manager-core
  • git-credential-manager-core.exe is in the PATH (or you need to use the full path C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I forgot to add this detail to the question (which I'll do now), but it's using Windows Credential Manager, so `git config credential.helper` returns `wincred` – Alex McCraw Feb 25 '22 at 13:30
  • @AlexMcCraw What version of Git are you using? I saw wincred decades earlier, when I was much younger ;) – VonC Feb 25 '22 at 15:01
  • @AlexMcCraw But anyway, simply replace credential-manager-core by wincred: any credential helper follows the same protocol. – VonC Feb 25 '22 at 15:02
  • Replacing it with `wincred` gives an error that it's not a valid command. That said I might just see if I can switch it to using git credential manager, this is in an enterprise environment and I'm not sure if it's actually installed or not, but if it is it seems like the easier path. – Alex McCraw Feb 27 '22 at 20:20
  • @AlexMcCraw "this is in an enterprise environment": what OS (Windows, I suppose) and Git version are you using in this "enterprise environment"? – VonC Feb 27 '22 at 20:44
  • Windows 10, git 2.28.0.windows.1 – Alex McCraw Feb 28 '22 at 14:43
  • @AlexMcCraw OK. I believe 2.28 (https://github.com/git-for-windows/git/releases/tag/v2.28.0.windows.1, July 2020) has the credential manager core in it. So you could try and switch to that. – VonC Feb 28 '22 at 17:07
  • Okay so it was actually already installed, just not configured to use it, but when I try to run the command `printf "host=remote.host.name\nprotocol=https\nusername=aUser\npasswprd=" | \ git credential-manager-core store` I get the error `fatal: No host provider available to service this request.` I even tried reinstalling git and the credential manager to see if something was hosed up there, but I'm getting the same error. It's proving to be weirdly hard to google, any ideas on that one? – Alex McCraw Feb 28 '22 at 22:00
  • @AlexMcCraw `remote.host.name` is accessible with HTTPS from where you are typing the `printf` command, right? – VonC Feb 28 '22 at 22:33
  • Yep, it's definitely accessible, I've tested it a few different ways – Alex McCraw Feb 28 '22 at 22:58
  • Well after installing a newer version of git and the credential manager, it all worked fine with the original command you gave, once I set it to use the credential manager. Thanks! – Alex McCraw Mar 01 '22 at 04:26
  • @AlexMcCraw Great! Well done. I have edited the answer to include that step. – VonC Mar 01 '22 at 07:03