gitlab--缓存 cache (二)

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: gitlab--缓存 cache

创建 job 的缓存和缓存策略


上面我们使用的是全局的缓存,我们也可以给某个 job 设置缓存,也可以设置缓存的策略 push 或者 pull

stages:
  - build1
  - build2
  - build3
  - test1
  - test2
  - deploy
build1:
  stage: build1
  tags:
    - build
  before_script:
    - ls 
    - ls app
  cache:
    key: build1 # 为缓存提供唯一的标识键
    paths:
      - app/a.txt # 将 app 下的 a.txt 文件创建一个缓存
      - app/b.txt # 将 app 下的 b.txt 文件创建一个缓存
  script:
    - ls
    - id
    - echo 'test123' >> app/a.txt # 创建了个文件,模拟编译产生的文件
    - echo 'test456' >> app/b.txt # 创建了个文件,模拟编译产生的文件
    - ls app
build2:
  stage: build2
  tags:
    - build
  before_script:
    - ls 
    - ls app
  cache:
    key: build2 # 为缓存提供唯一的标识键
    paths:
      - app/c.txt # 将 app 下的 c.txt 文件创建一个缓存
  script:
    - ls
    - id
    - echo 'test123' >> app/c.txt # 创建了个文件,模拟编译产生的文件
    - ls app
build3:
  stage: build3
  tags:
    - build
  before_script:
    - ls 
    - ls app
  cache:
    # key: build3 # 没有设置 key,将使用 default
    paths:
      - app/e.txt # 将 app 下的 c.txt 文件创建一个缓存
  script:
    - ls
    - id
    - echo 'test666' >> app/e.txt # 创建了个文件,模拟编译产生的文件
    - ls app
test1:
  stage: test1
  tags:
    - build
  before_script:
    - ls 
    - ls app
  script:
    - echo "run test"
    - echo 'test' >> app/c.txt # 创建了个文件
    - ls app # 在查看 app 下的内容
  cache:
    policy: pull # 缓存的策略是仅在作业开始时下载缓存,但在作业完成时从不上传更改
    key: build1
    paths: # 使用了 key,必须要有 paths,下载 a.txt 文件
      - app/a.txt
      - app/c.txt # 缓存 build1 里没有 c.txt 文件,所以不会下载。由于策略原因,c.txt 文件也不会上传到缓存里
test2:
  stage: test2
  tags:
    - build
  before_script:
    - ls 
    - ls app
  script:
    - echo "run test"
    - echo 'test' >> app/d.txt
    - ls app # 在查看 app 下的内容
  cache:
    policy: push # 缓存的策略是仅在作业完成时上传缓存,但在作业开始时从不下载缓存
    key: build2
    paths:
      - app/d.txt # 由于策略设置的是 push,所以会上传
      - app/c.txt # 由于设置的策略是 push,所以不会下载 build2 里的 c.txt 文件,上传缓存时会给出警告
deploy:
  stage: deploy
  tags:
    - build
  before_script:
    - ls 
    - ls app
  script:
    - echo "run deploy"
    - ls app # 在查看 app 下的内容
  retry:
    max: 2
    when:
      - script_failure

运行上面的流水线,查看日志,先来查看 build1 的日志


build1 日志

可以看到,重置缓存的时候是去 build1-protected 下面去下载缓存的


build2 日志

可以看到,重置缓存的时候是去 build2-protected 下面去下载缓存的


build3 日志


进入 runner 里查看下缓存

test1 日志


test2 日志



deploy 日志


相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
相关文章
|
4月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
1622 10
|
5月前
|
存储 缓存 NoSQL
Spring Cache缓存框架
Spring Cache是Spring体系下的标准化缓存框架,支持多种缓存(如Redis、EhCache、Caffeine),可独立或组合使用。其优势包括平滑迁移、注解与编程两种使用方式,以及高度解耦和灵活管理。通过动态代理实现缓存操作,适用于不同业务场景。
463 0
|
存储 缓存 NoSQL
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
228 2
|
缓存 弹性计算 NoSQL
【Azure Redis 缓存 Azure Cache For Redis】Redis连接池
【Azure Redis 缓存 Azure Cache For Redis】Redis连接池
149 0
|
缓存 NoSQL Redis
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
129 0
|
缓存 开发框架 NoSQL
【Azure Redis 缓存】VM 里的 Redis 能直接迁移到 Azure Cache for Redis ? 需要改动代码吗?
【Azure Redis 缓存】VM 里的 Redis 能直接迁移到 Azure Cache for Redis ? 需要改动代码吗?
166 0
|
缓存 NoSQL Unix
【Azure Redis 缓存】Azure Cache for Redis 中如何快速查看慢指令情况(Slowlogs)
【Azure Redis 缓存】Azure Cache for Redis 中如何快速查看慢指令情况(Slowlogs)
129 0
|
缓存 NoSQL Redis
【Azure Redis 缓存】Azure Cache for Redis 是否记录具体读/写(Get/Set)或删除(Del)了哪些key呢?
【Azure Redis 缓存】Azure Cache for Redis 是否记录具体读/写(Get/Set)或删除(Del)了哪些key呢?
141 0
|
存储 缓存 NoSQL
【Azure Redis 缓存】Azure Cache for Redis 专用终结点, 虚拟网络, 公网访问链路
【Azure Redis 缓存】Azure Cache for Redis 专用终结点, 虚拟网络, 公网访问链路
138 0
|
存储 缓存 NoSQL
【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?
【Azure Redis 缓存】Azure Cache for Redis服务中,除开放端口6379,6380外,对13000,13001,15000,15001 为什么也是开放的呢?
247 0