blueFast
blueFast

Reputation: 44351

GitLab cache does not reliably find matching files

My gitlab CI is as follows:

stages:
  - test

cache:
  key: ${CI_COMMIT_SHA}
  paths:
    - mymark

test:
  stage: test
  script:
    - ls -l
    - echo "hi" > mymark
    - ls -l
  tags:
    - myrunner
  only:
    - dev

The file mymark is created by the build scripts:

$ ls -l
total 76
-rw-r--r--  1 root root    3 Mar 15 10:48 mymark

But GitLab does not see it:

Creating cache 122f151d6b0a9d37cfa2172941d642e5c48287fc...
WARNING: mymark: no matching files                 
Created cache
Job succeeded

This seems to happen randomly: sometimes the file is found, sometimes not:

Creating cache 63d295dad175370aa61d13c4d2f3149e050df5e0...
mymark: found 1 matching files               
Created cache
Job succeeded

Upvotes: 5

Views: 2152

Answers (2)

MS Berends
MS Berends

Reputation: 5189

This is because cache can only be used for files inside your project, so even

cache:
  paths:
    - /my_root_path

will let GitLab CI look for /home/user/yourproject/my_root_path.

Upvotes: 3

Neil
Neil

Reputation: 25815

This can happen when you cd out of the original directory in any before_script or script directive.

Make sure you cd back to the original directory you were in so the cache code can see the paths its looking for.

Upvotes: 0

Related Questions