[英]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
确保您已经安装
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 时没有任何配置文件问题。
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.