2016-06-23 189 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文件,否則他們將不會加載。