【问题标题】:Cloning a private repo in Github Actions在 Github Actions 中克隆一个私有仓库
【发布时间】:2020-06-17 00:59:21
【问题描述】:

我正在尝试在 Github 操作中克隆另一个私人仓库。我在我正在运行操作的回购的秘密中设置了SECRET_USERSECRET_PASSWORD。在操作中我正在运行命令

git clone https://$SECRET_USER:$SECRET_PASSWORD@github.com/other-organization/other-repo.git

但出现错误

Cloning into 'other-repo'...
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/other-organization/other-repo.git/'
##[error]Process completed with exit code 128.

在 Github Actions 中,虽然我已经验证用户可以访问 https://github.com/other-organization/other-repo(这显然不是内部 repo 的真实 URL)。

【问题讨论】:

  • git clone https://$SECRET_USER:$SECRET_PASSWORD@github.com/other-organization/other-repo.git 在您的本地计算机上是否适合您?
  • 秘密应该像这样引用${{ secrets.SECRET_USER }},除非你的run步骤设置env变量。

标签: git github github-actions


【解决方案1】:

我在我的go.yml 中添加了一个 git 配置步骤,它成功了:

- name: Configure git
  env:
    TOKEN: ${{ secrets.ACCESS_TOKEN }}
  run: git config --global url."https://${TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

其中ACCESS_TOKENpersonal access token,而不是用户名/密码组合,因为我尝试访问的私有存储库需要启用 SSO 的令牌才能访问它,而不是用户名/密码组合。不幸的是,这在错误消息中并不明显,需要与人交谈才能了解此信息。

【讨论】:

    【解决方案2】:

    您可以使用git-credential-store 将您的凭据保存在文件中,以便 git 可以在需要时使用它。 在(我的情况)Podfile/specfile 中不需要修改 url。

    git config --global credential.helper store
    echo "https://$SECRET_USER:$SECRET_PASSWORD@github.com" > ~/.git-credentials
    

    我对将此类数据保存在纯文本文件中的感觉很复杂,但在 CI/CD 机器上,我认为这很好。我用它here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-16
      • 2018-10-20
      • 2022-08-08
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多