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

查看:29
本文介绍了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.我确实也插入了一次触摸命令,但是如果没有触摸命令,这不会改变下一次运行的任何内容.

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.

工件 - 用于将在阶段之间传递的阶段结果.Artifacts 旨在上传构建的一些已编译/生成的位,并且它们可以由任意数量的并发 Runners 获取.它们保证可用,并且可以在作业之间传递数据.它们也可以从 UI 中下载.

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天全站免登陆