在Github Actions中克隆私人仓库

时间:2020-03-04 13:53:50

标签: git github github-actions

我正在尝试在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(显然这不是内部存储库的真实URL)。

1 个答案:

答案 0 :(得分: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的令牌才能访问它,而不是用户名/密码组合。不幸的是,这在错误消息中并不明显,需要与人们交谈以学习此信息。