在asking on the GCM Github issues page之後,事實證明GCM不支持從文件讀取證書。
但是我的目標是允許非交互式的證書羣體,它確實支持以編程方式向GCM使用的Windows Credential Store添加證書。通過使用bundled libraries(binaries 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文件,否則他們將不會加載。