【问题标题】:Git Credential Manager for Windows and credentials in a file适用于 Windows 的 Git 凭据管理器和文件中的凭据
【发布时间】:2016-06-23 03:59:43
【问题描述】:

如何让Git Credential Manager (GCM) 从文件中读取 HTTPS Git URL 的凭据?我们需要这个来促进 Jenkins 作业的自动克隆操作。

背景

在升级到 Git for Windows v2.9.0 之前,我们已经在 Windows 上的 Git 1.7 中成功使用了 store 凭据存储。现在 CGM 总是要求提供凭据,导致 Jenkins 构建挂起。

我注意到 GCM docs 提到了 credential.interactive never 设置,但我如何告诉它从哪个文件读取凭据?该文件的格式是什么?

【问题讨论】:

    标签: git jenkins git-credential-winstore


    【解决方案1】:

    asking on the GCM Github issues page 之后发现 GCM 不支持从文件中读取凭据。

    但我的目标是允许非交互式的凭据填充,它确实支持以编程方式将凭据添加到 GCM 在后台使用的 Windows 凭据存储。通过使用bundled libraries (binaries here),我能够组合一个 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 克隆。

    注意:您需要使用“无限制”执行策略以及unblock GCM 中包含的 DLL 运行 Powershell 脚本,否则它们将无法加载。

    【讨论】:

      猜你喜欢
      • 2016-02-07
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多