1

I tried to find a solution for this problem but couldn't find any.

The issue:

We have image files in /public/img/InfoNews/example.png 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 and artifacts 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

  artifacts:
    paths:
      - .env
      - public/img/

EDIT:

I also tried

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

But it still deletes the files.

4
  • Can you paste the relevant bits in your .gitlab-ci.yml please?
    – Rekovni
    Jan 15, 2020 at 15:21
  • @Rekovni posted content of your file
    – Patric
    Jan 15, 2020 at 15:52
  • it removing the file from your local?
    – bahram
    Jan 16, 2020 at 10:12
  • @bahram I don't have the file locally, they are images that are uploaded on the remote machine. I assume gitlab-runner does a hard reset every time and removes everything that's not in the repo and I can't stop it
    – Patric
    Jan 16, 2020 at 10:19

1 Answer 1

7

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 .gitignore files -f forces the clean and -e excludes files from the clean, the ** means every file and folder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.