【问题标题】:error : You are not allowed to upload code while setting upstream错误:设置上游时不允许上传代码
【发布时间】:2022-01-23 10:39:22
【问题描述】:

我正在尝试使用git push 命令为 gitlab 中的一个分支设置上游

git push --set-upstream origin hotfix_master_$CI_COMMIT_SHA

这是我正在执行的命令集

    - echo $CI_COMMIT_SHA   // echo commit SHA 
    - echo "${GITLAB_USER_NAME}" // echo user name 
    - echo "${GITLAB_USER_EMAIL}" // echo user mail 
    - git checkout hotfix_master // get the current working tree/workspace for hotfix_master
    - git pull // pull the latest changes 
    - git checkout -b hotfix_master_$CI_COMMIT_SHA // create new branch from source as hotfix_master 
    - git fetch // get refs from remote and commit in local 
    - git push --set-upstream origin hotfix_master_$CI_COMMIT_SHA  // associate remote branches 

出现以下错误:

remote:您不能上传代码。致命:无法访问 'https://gitlab-ci-token:[MASKED]@gitlab.com/xxx/xxx-project.git/': 请求的 URL 返回错误:403

已经创建了个人访问令牌并且工作正常。开始从 commit_sha 创建分支时开始出现问题。不知道为什么?我检查了令牌没有过期。 在本地命令提示符下,一切正常

$ git push --set-upstream origin hotfix_master_xxxxxxxxxxxxxxxxxxxxxxx
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: To create a merge request for hotfix_master_xxxxxxxxxxxxxxxxxxxx, visit:
remote:   https://gitlab.com/xxx/xxx-project/-/merge_requests/new?merge_request%5Bsource_branch%5D=hotfix_master_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
remote:
To https://gitlab.com/xxx/xxx-project.git
 * [new branch]      hotfix_master_xxxxxxxxxxxxxxxxxxxx -> hotfix_master_xxxxxxxxxxxxxxxxxxxxx
Branch 'hotfix_master_xxxxxxxxxxxxxxxxxxx' set up to track remote branch 'hotfix_master_xxxxxxxxxxxxxxxxxxxx' from 'origin'.

无法理解为什么 gitlab CI 管道会失败。请建议

编辑 1

编辑 2

我现在创建了新令牌“gitlab-ci-token”,因为错误表明,它正在尝试使用名为“gitlab-ci-token”的令牌仍然无法正常工作

【问题讨论】:

  • git push --set-upstream 设置上游作为副作用。它的主要作用是上传新的提交。你——或者更确切地说,你的 CI 工作——没有这样做的权限。如果它应该具有权限,请检查您或您的管理员授予它的权限。
  • 我是唯一一个 git 项目的管理员/维护者,并且我已授予所有权限。见编辑 1。我正在使用 gitlab_token1
  • 表示从未使用过令牌。我需要在 git push 命令中提及用户名/密码吗?
  • 我没有使用 GitLab CI,但是您需要使用 GitLab-CI 提供的任何工具来设置所需的任何访问权限(ssh 或 https)。一般来说,如果使用ssh,则必须设置ssh;如果您使用的是 https,则必须创建凭据并设置在 Git 运行时生成它们的凭据助手。 (请记住,Git 本身不进行身份验证:它依赖于其他程序。)
  • 实际上不明白为什么它不起作用。我创建了新令牌“gitlab-ci-token”并授予所有访问权限。仍然是错误。为什么推送不起作用???

标签: git gitlab gitlab-ci


【解决方案1】:
https://gitlab-ci-token:[MASKED]@...

网址应该是:

https://oauth2:<the_token>@...

用户名是oauth2。用git remote set-url origin设置遥控器。

【讨论】:

  • 谢谢。但是我应该在哪里设置呢?在 git push 命令之前?错误发生在 git push 命令之后。
  • 在任何连接到远程并需要密码的命令之前。 before git push command ? 是的。无论如何,您在 gitlab-ci 中都没有设置令牌。
  • 谢谢。它奏效了
猜你喜欢
  • 1970-01-01
  • 2021-11-04
  • 2019-12-15
  • 1970-01-01
  • 2010-10-14
  • 2011-06-08
  • 2019-08-18
  • 2020-03-01
  • 2016-05-17
相关资源
最近更新 更多