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
相关产品推荐
相关产品推荐

