Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab-Ci: How could I share data between jobs

I want to share a file between two jobs and modify it if there are changed files. The python script compare the cache.json file with changes and modify the cahce file sometimes.

.gitlab-ci.yaml:

image: ubuntu

stages:
  - test

cache:
  key: one-cache
  paths:
    - cache.json

 job1:
   stage: test

script:
  # - touch cache.json
  - cat cache.json
  - python3 modify_json_file.py
  - cat cache.json

The problem is that it the cache.json file not exist at the next job run. I get the error message: cat: cache.json: No such file or directory. I did also insert once the touch command, but this doesn't change anything for the next run without the touch command.

Do I something wrong or don't I understand the cache at gitlab wrong.

like image 955
test42 Avatar asked May 15 '18 20:05

test42


1 Answers

I think you need artifacts and not cache.

From cache vs artifact:

cache - Use for temporary storage for project dependencies. Not useful for keeping intermediate build results, like jar or apk files. Cache was designed to be used to speed up invocations of subsequent runs of a given job, by keeping things like dependencies (e.g., npm packages, Go vendor packages, etc.) so they don't have to be re-fetched from the public internet. While the cache can be abused to pass intermediate build results between stages, there may be cases where artifacts are a better fit.

artifacts - Use for stage results that will be passed between stages. Artifacts were designed to upload some compiled/generated bits of the build, and they can be fetched by any number of concurrent Runners. They are guaranteed to be available and are there to pass data between jobs. They are also exposed to be downloaded from the UI.

like image 95
Ekans Avatar answered Sep 18 '22 11:09

Ekans