无法在github动作中运行git clone。

问题描述 投票:-1回答:1

我的密码和用户名设置如下

git config --global user.email $git_email
git config --global user.name $git_username
git config --global user.password $git_password

其中$git_email, $git_username, 和$git_password指向正确的环境变量。

Now when I try to run git clone I get the following error: 
Cloning into 'certificates'...
fatal: could not read Username for 'https://github.com': Device not configured

同样的方法在本地和 Travis CI 中都能正常工作,所以我不确定问题出在哪里。

git macos github continuous-integration
1个回答
1
投票

user.name 不是用户名,并且 user.password 不存在。 从 文件 对于 user.name:

请注意,这些变量的名称形式通常是指某种形式的个人名称。请参阅 git-commit(1) 和 git(1) 的环境变量部分,了解更多关于这些设置和 credential.username 选项,如果你正在寻找认证凭证。

那就是: user.name 应该是你的(人类)名字,而不是用户名。

因此,你被提示输入用户名和密码,但你得到的是一个失败,因为没有TTY来提示你。 在你的系统中,凭证可能已经保存在你的凭证帮助程序中,这就是为什么你没有看到提示。

如果你想克隆另一个版本库,你应该首先创建一个个人访问令牌,并将其存储在你的 CI 系统的秘密存储中(例如,作为一个环境变量,称为 TOKEN). PATs不会在你的密码改变时改变,可以独立于你的密码被撤销和轮换,并且比大多数密码更安全。

然后,在您的 CI 工具中,运行以下内容。

$ git config credential.helper '!f(){echo username=token; echo "password=$TOKEN";};f'

这将设置一个凭证助手来使用 TOKEN 环境变量作为你的密码。 确保环境变量被设置为你的克隆操作,事情就会正常进行。

© www.soinside.com 2019 - 2024. All rights reserved.