Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab-runner failed to remove permission denied

I'm setting up a CI/CD pipeline with Gitlab. I've installed gitlab-runner on a Digital Ocean Ubuntu 18.04 droplet and gave permissions in /etc/sudoers to the gitlab-runner as:

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:

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:

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
like image 484
Rexcirus Avatar asked Feb 24 '20 14:02

Rexcirus


People also ask

Why is my gitlab runner not picking up jobs?

You can also check if your runner is allowed to run untagged jobs - you can do that under Admin and then edit it to see if that option is enabled. The runner is a specific runner for the project and not a shared one.

Can run untagged jobs gitlab runner?

Set a runner to run untagged jobsGo to the project's Settings > CI/CD and expand the Runners section. Find the runner you want to pick untagged jobs and make sure it's enabled. Click the pencil button. Check the Run untagged jobs option.

Where are gitlab runner logs stored?

By default, all job traces (logs) are saved to /var/opt/gitlab/gitlab-ci/builds and /home/git/gitlab/builds for Omnibus packages and installations from source respectively.


2 Answers

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.

like image 97
Vlad Mazurkov Avatar answered Oct 19 '22 17:10

Vlad Mazurkov


I would recommend setting a GIT_STRATEGY to none in the afflicted job.

like image 1
Grumbunks Avatar answered Oct 19 '22 17:10

Grumbunks