Gitlab-runner 未能删除权限被拒绝

Rex*_*rus 13 continuous-integration gitlab docker-compose

我正在使用 Gitlab 设置 CI/CD 管道。我已经在 Digital Ocean Ubuntu 18.04 Droplet 上安装了 gitlab-runner,并向/etc/sudoersgitlab-runner 授予了权限,如下所示:

gitlab-runner ALL=(ALL:ALL)ALL
Run Code Online (Sandbox Code Playgroud)

对关联存储库的第一次提交正确构建了 docker-compose(应用程序本身是 Django+postgres),但以下提交无法清理以前的构建并失败:

Running with gitlab-runner 12.8.0 (1b659122)
on ubuntu-s-4vcpu-8gb-fra1-01 52WypZsE
Using Shell executor...
00:00
Running on ubuntu-s-4vcpu-8gb-fra1-01...
00:00
Fetching changes with git depth set to 50...
00:01
 Reinitialized existing Git repository in /home/gitlab-runner/builds/52WypZsE/0/lorePieri/djangocicd/.git/
 From https://gitlab.com/lorePieri/djangocicd
  * [new ref]         refs/pipelines/120533457 -> refs/pipelines/120533457
    0072002..bd28ba4  develop                  -> origin/develop
 Checking out bd28ba46 as develop...
 warning: failed to remove app/staticfiles/admin/img/selector-icons.svg: Permission denied
 warning: failed to remove app/staticfiles/admin/img/search.svg: Permission denied
 warning: failed to remove app/staticfiles/admin/img/icon-alert.svg: Permission denied
 warning: failed to remove app/staticfiles/admin/img/tooltag-arrowright.svg: Permission denied
 warning: failed to remove app/staticfiles/admin/img/icon-unknown-alt.svg: Permission denied
Run Code Online (Sandbox Code Playgroud)

这是 .gitlab-ci.yml 文件的相关部分:

image: docker:latest
services:
  - docker:dind

stages:
  - test
  - deploy_staging
  - deploy_production

step-test:
  stage: test
  before_script:
    - export DYNAMIC_ENV_VAR=DEVELOP
  only:
    - develop
  tags:
    - develop
  script:
    - echo running tests in $DYNAMIC_ENV_VAR
    - sudo apt-get install -y python-pip
    - sudo pip install docker-compose
    - sudo docker image prune -f
    - sudo docker-compose -f docker-compose.yml build --no-cache
    - sudo docker-compose -f docker-compose.yml up -d
    - echo do tests now
    - sudo docker-compose exec -T web python3 -m coverage run --source='.' manage.py test

...
Run Code Online (Sandbox Code Playgroud)

我尝试过的:

usermod -aG docker gitlab-runner
sudo service docker restart
Run Code Online (Sandbox Code Playgroud)

小智 15

对我来说最好的解决方案是添加

pre_clone_script = "sudo chown -R gitlab-runner:gitlab-runner ."
Run Code Online (Sandbox Code Playgroud)

即使/etc/gitlab-runner/config.toml 您在执行上一个作业后没有权限,它也会在清理工作目录并克隆存储库之前设置正确的权限。

  • 将其添加到您的跑步者的 [[runners]] 部分。 (4认同)

Gru*_*nks 1

我建议在受影响的作业中将 GIT_STRATEGY 设置为 none。