Gitlab-runner removes files on remote, cache and untracked: true didn't help

We have image files in /public/img/InfoNews/example.png, those files are not part of the repo and every time we push an update gitlab-runner removes those files on the remote.

We have /public/img/InfoNews in our .gitignore this prevents git from uploading local files but not from deleting remote files in that folder for some reason.

I tried to add this path to the cache in .gitlab-ci.yml without success

A push in the right direction is appreciated.

Our .gitlab-ci.yml :

cache:
  paths:
    - vendor/
    - public/img/

deploy:
  stage: deploy
  script:
    - php artisan cache:clear
    - rm -rf vendor/
    - composer install
    - echo "$env" > "$(pwd)/.env"
    - php artisan migrate

I also tried

cache:
  untracked: true
  paths:
    - vendor/
    - public/img/

But it still deletes the files.

1 Like

I fixed it myself.

Gitlab-runner runs git clean after checkout and ignores .gitignorefiles per default for whatever reason.

To prevent files from being deleted you have to add this to your gitlab-ci.yml`:

variables:
  GIT_CLEAN_FLAGS: -x -f -e public/**

-x ignores gitfiles -f forces the clean and -e excludes files from the clean, the ** means every file and folder

2 Likes