2016-06-23 117 views
0

如何让Git Credential Manager(GCM)从文件中读取HTTPS Git URL的凭据?我们需要此功能来促进Jenkins作业的自动克隆操作。Windows的Git凭据管理器和文件中的凭证

背景升级到Git for Windows v2.9.0

我们已经成功地使用Git中1.7 store凭证存储在Windows之前。现在CGM总是要求导致Jenkins构建挂起的证书。

我注意到GCM docs提到credential.interactive never设置,但我怎么能告诉它从哪个文件读取凭据?它在该文件中期望的格式是什么?

回答

0

asking on the GCM Github issues page之后,事实证明GCM不支持从文件读取证书。

但是我的目标是允许非交互式的证书群体,它确实支持以编程方式向GCM使用的Windows Credential Store添加证书。通过使用bundled librariesbinaries here)我是能够把一个PowerShell脚本,使我们的厨师添加机配置中的凭据:

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) 
} 

这使得詹金斯奴隶,而无需用户交互进行Git的克隆。

注:您需要的“无限制”执行策略运行PowerShell脚本,以及包含在GCM unblock的DLL文件,否则他们将不会加载。