Gitlab-Ci: How could I share data between jobs

23,905

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.

Share:
23,905
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • Dennis V
    Dennis V over 2 years
    Good answer, but it would be better if you present an example.