You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab CI(Shell Runner)如何保存各阶段各作业的输出文件

GitLab CI 作业输出文件持久化到 results 目录

修改后的完整流水线配置

preprocessing_job1:
  tags:
    - block_autotest
  stage: preprocessing
  script:
    - <some calculations outputting some files to sandbox directory within repo>
    - mkdir -p results/$CI_JOB_NAME
    - mv sandbox/* results/$CI_JOB_NAME/

preprocessing_job2:
  tags:
    - block_autotest
  stage: preprocessing
  script:
    - <other calculations outputting other files to sandbox directory within repo>
    - mkdir -p results/$CI_JOB_NAME
    - mv sandbox/* results/$CI_JOB_NAME/

runtime_job1:
  tags:
    - block_autotest
  stage: runtime
  script:
    - <some more calculations outputting some more files to sandbox directory within repo>
    - mkdir -p results/$CI_JOB_NAME
    - mv sandbox/* results/$CI_JOB_NAME/

runtime_job2:
  tags:
    - block_autotest
  stage: runtime
  script:
    - <new calculations outputting new files to sandbox directory within repo>
    - mkdir -p results/$CI_JOB_NAME
    - mv sandbox/* results/$CI_JOB_NAME/

核心逻辑说明

  • 利用GitLab CI内置环境变量 $CI_JOB_NAME 自动获取当前作业名称,无需手动为每个作业指定目录名,保证配置的通用性
  • mkdir -p results/$CI_JOB_NAME 递归创建目标目录,避免因目录层级不存在导致后续移动命令失败
  • mv sandbox/* results/$CI_JOB_NAME/ 将sandbox目录下所有输出文件转移到对应作业的results子目录,实现作业输出的持久化保存

额外优化提示

如果sandbox目录包含子目录或隐藏文件,可将移动命令替换为 mv sandbox/.* sandbox/* results/$CI_JOB_NAME/,确保所有内容都被转移;若需要清理sandbox目录残留文件,可添加 rm -rf sandbox/* 命令,但通常CI会自动清理作业环境,无需额外操作。

内容的提问来源于stack exchange,提问作者IzaeDA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 20:02:34