简体   繁体   English

Windows的Git Credential Manager和文件中的凭据

[英]Git Credential Manager for Windows and credentials in a file

How can I get the Git Credential Manager (GCM) to read credentials from a file for HTTPS Git URLs? 如何获得Git凭据管理器 (GCM)从HTTPS Git URL的文件中读取凭据? We need this in order to facilitate automatic cloning operations for Jenkins jobs. 我们需要这样做,以便于对Jenkins作业进行自动克隆操作。

Background 背景

We have been successfully using the store credential store in Git 1.7 on Windows prior to upgrading to Git for Windows v2.9.0 . 在升级到适用于Windows v2.9.0的Git之前,我们已经在Windows的Git 1.7中成功使用了store凭证存储。 Now the CGM always asks for credentials causing the Jenkins build to hang. 现在,CGM总是要求提供凭证,导致Jenkins建筑物挂起。

I notice the GCM docs mention a credential.interactive never setting but how can I tell it which file to read the credentials from? 我注意到GCM 文档提到了credential.interactive never设置,但如何告诉它从哪个文件读取凭据? And what format is it expecting in that file? 该文件期望什么格式?

After asking on the GCM Github issues page it turns out that the GCM does not support reading credentials from a file. GCM Github问题页面上询问后,事实证明GCM不支持从文件读取凭据。

But my goal is to allow non-interactive population of credentials and it does support programmatically adding credentials to the Windows Credential Store that GCM uses under the hood. 但是我的目标是允许非交互式填充凭据,并且它确实支持以编程方式将凭据添加到GCM在后台使用的Windows凭据存储中。 By using the bundled libraries ( binaries here ) I was able to put together a Powershell script that allowed us to add credentials during machine provisioning by Chef : 通过使用捆绑的库这里二进制文件 ),我可以整理一个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)
}

This allows the Jenkins slave to perform Git clones without user interaction. 这使Jenkins从属无需用户交互即可执行Git克隆。

Note: You will need to run the Powershell script with the "Unrestricted" execution policy as well as unblock the DLLs included in the GCM otherwise they won't load. 注意:您将需要使用“不受限制”的执行策略来运行Powershell脚本,并取消阻止 GCM中包含的DLL,否则它们将无法加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GIT 凭据从 Windows 凭据管理器中消失 - GIT credentials disappearing from Windows Credential Manager 使用适用于Windows的Git Credential Manager保存GIT凭据 - 不起作用 - Save GIT Credentials using Git Credential Manager for Windows - Not working Jenkins无法从Windows凭据管理器检测到GIT凭据 - Jenkins does not detect GIT credentials from Windows Credential manager 如何在 Windows 的 Git Credential Manager 中的每个 repo 本地存储凭据? - How to store credentials locally per repo in Git Credential Manager for Windows? 使用 git 凭据填充命令时,从 Windows 凭据管理器中删除凭据仍然显示凭据 - Deleting the credentials from Windows Credential Manager still displayed credentials when using git credential fill command Git 用于 Windows - 凭证管理器问题 - Git for Windows - issue with credential manager Windows上的Git凭据帮助器,无需输入凭据 - Git Credential Helper on Windows without asking for credentials 如何确定Windows版Git Credential Manager的版本? - How to determine the version of Git Credential Manager for Windows? 从Windows的Git Credential Manager中注销 - Logging out from Git Credential Manager for Windows Git for Windows静默安装,无需“凭据管理器” - Git for Windows silent installation without “Credential Manager”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM