# 定义流水线的阶段 stages: - test - deploy # === 作业 1: 测试阶段 (运行压测) === benchmark_job: stage: test # 关键:指定使用我们注册的 Runner tags: - test script: - echo "Starting ResNet50 benchmark..." # 直接在 Runner 容器的 shell 中执行 Python 脚本 - source /opt/dtk/env.sh - python benchmark_resnet50.py - echo "Benchmark finished." # 定义产物:将脚本生成的 results.json 文件保存下来 artifacts: paths: - results.json # 产物保存 1 周,过期自动删除 expire_in: 1 week # === 作业 2: 部署阶段 (展示结果) === # 这个作业的目的是展示如何使用上一个作业的产物 deploy_job: stage: deploy tags: - test # 只在主分支上运行,模拟一个正式的部署或报告流程 rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # GitLab 会自动将上一个作业 (benchmark_job) 的产物下载到此作业的工作目录中 script: - echo "Displaying benchmark results from the artifact..." - cat results.json - echo "Results have been archived." environment: name: performance-report # 这个链接会指向 CI/CD 的作业列表,方便追溯 url: https://gitlab.com/your-username/resnet50-benchmark/-/jobs