简体   繁体   English

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

[英]Gitlab-runner failed to remove permission denied

I'm setting up a CI/CD pipeline with Gitlab.我正在使用 Gitlab 设置 CI/CD 管道。 I've installed gitlab-runner on a Digital Ocean Ubuntu 18.04 droplet and gave permissions in /etc/sudoers to the gitlab-runner as:我已经在 Digital Ocean Ubuntu 18.04 droplet 上安装了 gitlab-runner,并在/etc/sudoers中为 gitlab-runner 授予了权限:

gitlab-runner ALL=(ALL:ALL)ALL

The first commit to the associated repository correctly build the docker-compose (the app itself is Django+postgres), but following commits are not able to clean previous builds and fail:对关联存储库的第一次提交正确构建了 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

This is the relevant portion of the .gitlab-ci.yml file:这是 .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

...

What I've tried:我试过的:

usermod -aG docker gitlab-runner
sudo service docker restart

The best solution for me was adding对我来说最好的解决方案是添加

pre_clone_script = "sudo chown -R gitlab-runner:gitlab-runner ."

into /etc/gitlab-runner/config.toml Even if you won't have permissions after a previous job it'll set correct permissions before cleaning up the workdir and cloning the repo.进入/etc/gitlab-runner/config.toml即使您在上一份工作后没有权限,它也会在清理工作目录和克隆 repo 之前设置正确的权限。

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

I have had the exact same problem.我遇到了完全相同的问题。 Therefore I will explain how it was resolved in details.因此,我将详细解释它是如何解决的。

Try finding your config.toml file and run the gitlab-runner command with root privileges, since permission denied is a very common UNIX-based operating systems error.尝试找到您的config.toml文件并以 root 权限运行gitlab-runner命令,因为权限被拒绝是一个非常常见的基于 UNIX 的操作系统错误。

After finding the location of config.toml pass it:找到config.toml的位置后传递它:

sudo gitlab-runner run --config <absolute_location_of_config_toml>

PS You can find all config.toml file easily using locate config.toml command. PS您可以使用locate config.toml命令轻松找到所有config.toml文件。 Make sure you have already installed by executing sudo apt-get install mlocate通过执行sudo apt-get install mlocate确保您已经安装

  1. After facing to permission denied error, I have tried using sudo gitlab-runner run instead of gitlab-runner , but it has its own problem:面对permission denied错误后,我尝试使用sudo gitlab-runner run而不是gitlab-runner ,但它有自己的问题:

     ERROR: Failed to load config stat /etc/gitlab-runner/config.toml: no such file or directory builds=0

    while executing gitlab-runner without root permissions doesn't have any config file problem.在没有 root 权限的情况下执行 gitlab-runner 时没有任何配置文件问题。

  2. Try implementing the ways and solutions as @Grumbanks and @vlad-Mazurkov mentioned.尝试实施@Grumbanks 和@vlad-Mazurkov 提到的方法和解决方案。 But they didn't work properly.但它们没有正常工作。

It MAY be because you write a file in cloned out codebase.这可能是因为您在克隆出的代码库中编写了一个文件。 What I do is simply create another directory outside of gitlab-runner directory:我所做的只是在 gitlab-runner 目录之外创建另一个目录:

WORKSPACE_DIR="/home/abcd_USER/a/b"
rm -rf $WORKSPACE_DIR
mkdir -p $WORKSPACE_DIR
cd $WORKSPACE_DIR
ls -la
git clone ..................
AND DO whatever 

I never faced the issue again.我再也没有遇到过这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 gitlab-runner local - 没有这样的命令 - gitlab-runner locally - No such command sh Gitlab-runner 无法执行第二项工作 - Gitlab-runner fails to perform second job Gitlab-Runner 向 docker 容器发出命令 - Gitlab-Runner issue commands to docker containers maven:来自 gitlab-runner 的最新图像,带有 docker 执行器“无法连接到 gitlab 连接被拒绝”使用 ZBAEDBAE645E0857 - maven:latest image from gitlab-runner with docker executer “Failed to connect to gitlab Connection refused” using docker-compose docker-compose postgres卷将所有权更改为gitlab-runner - docker-compose postgres volume changes ownership to gitlab-runner 如何在 gitlab-runner 中发布端口? - How can I publish a port in a gitlab-runner? Gitlab-runner:在 root 中找不到 docker 或 docker-compose 但它们已经安装 - Gitlab-runner: docker or docker-compose not found in root but they already installed 如何在 gitlab-runner 容器内运行的 docker 中的 docker 中运行 docker-compose? - How to run docker-compose inside docker in docker which runs inside gitlab-runner container? 如何为 gitlab-runner CI 安装/重用 docker-compose 秘密? - How to mount/reuse docker-compose secrets for gitlab-runner CI? 在 Gitlab CI runner / Google Cloud 中创建 React 应用程序构建失败 - Create react app build failed in Gitlab CI runner / Google cloud
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM