【问题标题】:Unable to run git clone in github actions无法在 github 操作中运行 git clone
【发布时间】:2020-07-27 17:40:18
【问题描述】:

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

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 github-actions


    【解决方案1】:

    user.name 不是用户名,user.password 不存在。来自documentation 为user.name:

    请注意,这些变量的名称形式通常指的是个人姓名的某种形式。有关这些设置的更多信息,请参阅 git-commit(1) 和 git(1) 的环境变量部分,如果您正在寻找身份验证凭据,请参阅 credential.username 选项。

    也就是说,user.name 应该是您的(人名),而不是用户名。

    因此,系统会提示您输入用户名和密码,但您遇到了失败,因为没有 TTY 可以提示您。在您的系统上,凭据可能已经保存在您的凭据助手中,这就是您看不到提示的原因。

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

    然后,在您的 CI 工具中,运行以下命令:

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

    这将设置一个凭证助手,以使用 TOKEN 环境变量中的令牌作为您的密码。确保为您的克隆操作设置了环境变量,并且一切正常。

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2021-05-27
      • 2020-01-10
      • 2018-05-31
      • 2019-10-16
      • 1970-01-01
      • 2012-02-03
      相关资源
      最近更新 更多