简体   繁体   English

从命令行将范围 PAT 添加到 git 凭证助手

[英]Add scoped PAT to git credential helper from command line

I have a Gitlab CI pipeline that's building a Unity project which has packages being pulled from a git repository.我有一个 Gitlab CI 管道,它正在构建一个 Unity 项目,其中包含从 git 存储库中提取的包。 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).有许多软件包,但它们都属于两个组中的一个,我可以获得两者的 PAT(由于某些其他限制,我无法在此特定实例中使用 SSH 密钥)。 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. Unity 使用 git 凭据管理器对包进行身份验证(详细信息),但我不确定如何从命令行实际将这些凭据添加到帮助程序。

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 .跑步者在 Windows 10 机器上使用 Shell 执行程序,我可以使用环境变量注入 PAT,但我不知道该怎么做的部分是将它们添加到凭证管理器中,在这种情况下它们将需要将范围限定为类似于此答案的特定组 URL。 The git installation on this machine is also configured to use the Windows Credential Manager.此机器上的 git 安装也配置为使用 Windows Credential Manager。

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) (正如OP Alex McCraw评论的,这需要为 Windows 2.35.1.2 安装最新的 Git ,在撰写本文时,2022 年第一季度)

This assume that, when executed on a Windows 10 machine:这假设,当在 Windows 10 机器上执行时:

  • git config credential.helper returns credential-manager-core git config credential.helper返回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 ) git-credential-manager-core.exe在 PATH 中(或者您需要使用完整路径C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM