[英]Git Credential Manager for Windows and credentials in a file
如何获得Git凭据管理器 (GCM)从HTTPS Git URL的文件中读取凭据? 我们需要这样做,以便于对Jenkins作业进行自动克隆操作。
背景
在升级到适用于Windows v2.9.0的Git之前,我们已经在Windows的Git 1.7中成功使用了store
凭证存储。 现在,CGM总是要求提供凭证,导致Jenkins建筑物挂起。
我注意到GCM 文档提到了credential.interactive never
设置,但如何告诉它从哪个文件读取凭据? 该文件期望什么格式?
在GCM Github问题页面上询问后,事实证明GCM不支持从文件读取凭据。
但是我的目标是允许非交互式填充凭据,并且它确实支持以编程方式将凭据添加到GCM在后台使用的Windows凭据存储中。 通过使用捆绑的库 ( 这里是二进制文件 ),我可以整理一个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)
}
这使Jenkins从属无需用户交互即可执行Git克隆。
注意:您将需要使用“不受限制”的执行策略来运行Powershell脚本,并取消阻止 GCM中包含的DLL,否则它们将无法加载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.