Gitlab-Ci:如何在作业之间共享数据 [英] Gitlab-Ci: How could I share data between jobs

查看:927
本文介绍了Gitlab-Ci:如何在作业之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在两个作业之间共享一个文件,如果文件已更改,请对其进行修改. python脚本将cache.json文件与更改进行比较,有时会修改cahce文件.

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

问题在于cache.json文件在下一次作业运行时不存在.我收到错误消息:cat: cache.json: No such file or directory.我也确实插入了一次touch命令,但是如果没有touch命令,则下次运行不会改变任何内容.

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.

我是不是出错了?还是我不理解gitlab上的cache.

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

推荐答案

我认为您需要工件而不是缓存.

I think you need artifacts and not cache.

来自缓存与人工产物:

缓存-用于临时存储项目相关项.对于保留中间生成结果(如jar或apk文件)没有用.缓存旨在通过保留诸如依赖项(例如npm软件包,Go供应商软件包等)之类的东西来加速给定作业的后续运行的调用,因此不必从公共场所重新获取它们.互联网.虽然可以滥用缓存在阶段之间传递中间的构建结果,但在某些情况下,工件更适合.

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.

工件-用于在阶段之间传递的阶段结果.工件被设计为上载构建的一些已编译/生成的位,并且可以由任意数量的并行Runner获取.它们保证可用,并且可以在作业之间传递数据.它们也可以从用户界面下载.

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.

这篇关于Gitlab-Ci:如何在作业之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆