[英]Git Credential Manager for Windows and credentials in a file
How can I get the Git Credential Manager (GCM) to read credentials from a file for HTTPS Git URLs? 如何获得Git凭据管理器 (GCM)从HTTPS Git URL的文件中读取凭据? We need this in order to facilitate automatic cloning operations for Jenkins jobs.
我们需要这样做,以便于对Jenkins作业进行自动克隆操作。
Background 背景
We have been successfully using the store
credential store in Git 1.7 on Windows prior to upgrading to Git for Windows v2.9.0 . 在升级到适用于Windows v2.9.0的Git之前,我们已经在Windows的Git 1.7中成功使用了
store
凭证存储。 Now the CGM always asks for credentials causing the Jenkins build to hang. 现在,CGM总是要求提供凭证,导致Jenkins建筑物挂起。
I notice the GCM docs mention a credential.interactive never
setting but how can I tell it which file to read the credentials from? 我注意到GCM 文档提到了
credential.interactive never
设置,但如何告诉它从哪个文件读取凭据? And what format is it expecting in that file? 该文件期望什么格式?
After asking on the GCM Github issues page it turns out that the GCM does not support reading credentials from a file. 在GCM Github问题页面上询问后,事实证明GCM不支持从文件读取凭据。
But my goal is to allow non-interactive population of credentials and it does support programmatically adding credentials to the Windows Credential Store that GCM uses under the hood. 但是我的目标是允许非交互式填充凭据,并且它确实支持以编程方式将凭据添加到GCM在后台使用的Windows凭据存储中。 By using the bundled libraries ( binaries here ) I was able to put together a Powershell script that allowed us to add credentials during machine provisioning by Chef :
通过使用捆绑的库 ( 这里是二进制文件 ),我可以整理一个Powershell脚本,该脚本使我们可以在Chef进行机器配置期间添加凭据:
Add-Type -Path 'c:\path\to\gcm-v1.4.0\Microsoft.Alm.Authentication.dll'
$credentials = New-Object -TypeName Microsoft.Alm.Authentication.Credential('someuser', 'secret')
$targetUri = New-Object -TypeName Microsoft.Alm.Authentication.TargetUri('https://git.example.com/projects')
$namespace = "git"
$secretStore = New-Object -TypeName Microsoft.Alm.Authentication.SecretStore($namespace, $null, $null, $null)
$foundCredentials = $null
$secretStore.ReadCredentials($targetUri, [ref] $foundCredentials)
if ($foundCredentials -ne $null) {
echo "Credentials already found, not inserting"
} else {
echo "Inserting stored credentials"
$secretStore.WriteCredentials($targetUri, $credentials)
}
This allows the Jenkins slave to perform Git clones without user interaction. 这使Jenkins从属无需用户交互即可执行Git克隆。
Note: You will need to run the Powershell script with the "Unrestricted" execution policy as well as unblock the DLLs included in the GCM otherwise they won't load. 注意:您将需要使用“不受限制”的执行策略来运行Powershell脚本,并取消阻止 GCM中包含的DLL,否则它们将无法加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.