gitlab runner The requested URL returned error: 403

gitlab runner The requested URL returned error: 403

我目前正在使用 gitlab.com(不是本地安装)和他们的多运行器进行 CI 集成。这对我的一个项目很有效,但对另一个项目却失败了。

我的主机使用 2012R2,MSBuild 版本为 14.0.23107.0。我知道下面的错误显示 403,这是一条访问被拒绝的消息。我的问题是找到要更改的权限设置。

错误信息:

Running with gitlab-ci-multi-runner 1.5.3 (fb49c47) Using Shell executor... Running on WIN-E0ORPCQUFHS...

Fetching changes...

HEAD is now at 6a70d96 update runner file remote: Access denied fatal: unable to access 'https://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlab.com/##REDACTED##/ADInactiveObjectCleanup.git/': The requested URL returned error: 403 Checking out 60ea1410 as Production...

fatal: reference is not a tree: 60ea1410dd7586f6ed9535d058f07c5bea2ba9c7 ERROR: Build failed: exit status 128

gitlab-ci.yml 文件:

variables:
  Solution: ADInactiveObjectCleanup.sln

before_script:
  #- "echo off"
  #- 'call "%VS120COMNTOOLS%\vsvars32.bat"'
  ## output environment variables (usefull for debugging, propably not what you want to do if your ci server is public)
  #- echo.
  #- set
  #- echo.

stages:
  - build
  #- test
  #- deploy

build:
  stage: build
  script:
  - echo building...
  - '"%ProgramFiles(x86)%\MSBuild.0\Bin\msbuild.exe" "%Solution%" /p:Configuration=Release'
  except:
  #- tags

这看起来您需要添加一个 cd 命令来将当前目录打印到您的 before_script。然后修复权限以访问该文件夹的父级。如果您将 gitlab runner 安装到 c:\glrunner,可能是您需要修复 c:\glrunner\builds 权限。

第二个问题是您可能需要通过删除构建文件夹来强制执行新的 git 克隆。

您可能希望将 gitlab runner 服务的登录凭据更改为 gitlabuser,这应该是一个非管理员帐户,它可能比本地系统帐户拥有更少的权限您的 gitlab runner 默认使用。

如果您想知道谁登录了,请将 set 也添加到您的 before_script,您将获得一个环境变量转储。从中您可以看到登录了哪个帐户,以及它的 USERPROFILE 在哪里以及其他内容。

为了解决这个问题,我必须将自己添加为项目成员。这是一个私人回购。我不确定这是否导致跑步者因不同的权限设置而失败,但很有可能。

gitlab 上的帮助 article 概述了这个问题。

With the new permission model in place, there may be times that your build will fail. This is most likely because your project tries to access other project's sources, and you don't have the appropriate permissions. In the build log look for information about 403 or forbidden access messages.

As an Administrator, you can verify that the user is a member of the group or project they're trying to have access to, and you can impersonate the user to retry the failing build in order to verify that everything is correct.

在项目页面点击设置齿轮,然后点击成员。将您自己(或用户生成的构建)添加为项目的成员。我使用了 "Master" 角色,但基于 this document 您可能至少可以使用 "Reporter" 角色。报告者角色是仍然可以访问 "Pull project code." 的最低权限。这消除了我的 403 错误并允许我继续。

我也遇到了这个问题

fatal: unable to access 'http://gitlab-ci-token:xxxx.git':The Requested URL returned error:403
ERROR: Job Failed: command terminated with exit code 1

但是上面回答的原因好像不太一样,因为我的账号是管理员,cijob拉项目报错403,因为管理员账号不是项目成员,添加为项目成员将不再报这个错误。

ci_build_permissions

可能是你的 ISP ip 被 GitLab 屏蔽了。

在您的系统上设置美国 DNS,然后重试。

依赖存储库

作业环境变量CI_JOB_TOKEN可用于 验证依赖存储库的任何克隆。例如:

git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/<user>/<mydependentrepo>.git

它也可以用于系统范围的身份验证 (仅在 docker 容器中执行此操作,它将覆盖 ~/.netrc):

echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc