【问题标题】:Push to Gitlab with access token using Github Actions使用 Github Actions 推送到带有访问令牌的 Gitlab
【发布时间】:2020-11-28 05:03:38
【问题描述】:

首先,我对 Github Actions 很陌生。

我试图使用 Github Actions 自动将我的 repo 推送到带有访问令牌的 Gitlab。但是,我总是收到错误remote: HTTP Basic: Access denied fatal: Authentication failed for 'https://gitlab.com/chuang_/jskara-web.git/'

我尝试了GitLab remote: HTTP Basic: Access denied and fatal Authenticationgit config --system --unset credential.helper 中的解决方案,但是如果我将该行放入 .yml 中,它将中断并返回错误代码 5。如果我不放入该行,我将收到错误如上所述。

我的 .yml 文件有尝试过的历史记录:https://github.com/ChuangSheep/javascript-kara-web/blob/master/.github/workflows/pushToGitlab.yml

这是我最近的尝试

name: PushGitlab

on:
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
      with: 
        fetch-depth: 0
      env: 
        token: ${{ secrets.GITLAB_ACCESS_TOKEN }}

    - name: Push To Gitlab
      run: |
        echo Starting to push repo to gitlab
        git config user.name "ChuangSheep"
        git config user.email "44814054+ChuangSheep@users.noreply.github.com"
        git remote set-url origin "https://oauth2:${token}@gitlab.com/chuang_/jskara-web.git"
        git push origin master

【问题讨论】:

    标签: git gitlab github-actions


    【解决方案1】:

    尝试将带有令牌的 env 块移动到“推送到 Gitlab”步骤。目前您将远程 url 设置为 https://oauth2:@gitlab.com/chuang_/jskara-web.git,因为永远不会设置 token 变量。

    【讨论】:

    • 谢谢你,它成功了。我误解了environmental variable 的含义。
    猜你喜欢
    • 2021-01-02
    • 2021-08-07
    • 1970-01-01
    • 2019-08-24
    • 2021-06-01
    • 2021-11-27
    • 2021-10-18
    • 2019-08-22
    • 2021-12-23
    相关资源
    最近更新 更多