我有一个 .gitlab-ci.yml
文件,我想用它来运行合并请求验证脚本。在 CI 中应该使用相同的脚本,但只有在那里结果才应该发布到 gitlab 页面。此外,仅对于 CI,应缓存结果。
这是当前 .gitlab-ci.yml
的简化版本:
pages:
stage: deploy
script:
- mkdir public/
- touch public/file.txt
artifacts:
paths:
- public
only:
- master
cache:
paths:
- fdroid
(实际代码位于 fdroid-firefox gitlab 存储库中。)
管道的触发方式有两种。根据这一点,我想或不想发布到页面:
script
部分,但我不想发布或缓存结果(否则,任何有权创建合并请求的人都可能覆盖 gitlab 页面内容)。master
分支后并按照计划触发)。在这种情况下,我希望缓存结果并更新 gitlab 页面。我已经尝试过拆分阶段:
stages:
- build
- deploy
build_repo:
stage: build
script:
- mkdir public/
- touch public/file.txt
pages:
stage: deploy
script: echo "publish to Gitlab pages"
artifacts:
paths:
- public
only:
- master
cache:
paths:
- fdroid
(原始 .gitlab-ci.yml
文件)
但是通过这样做,pages:deploy
阶段失败了,因为它无法访问 build
阶段的结果。 pages:deploy
阶段显示一个错误符号,并在工具提示上显示 missing pages artifacts
。 (real world log)。
日志说:
Uploading artifacts for successful job
00:01
Uploading artifacts...
WARNING: public: no matching files
ERROR: No files to upload
我无权访问构建阶段的结果,我做错了什么?
如何在两种情况下都运行 script
部分,但仍仅从 master
分支部署到页面?
答案 0 :(得分:1)
您没有将您的 public
路径工件保存在您的 build job 中。这就是他们在下一个 deploy
阶段的 pages
工作中失踪的原因。
你有这个:
build_repo:
stage: build
script:
- your script
尝试像这样在构建作业中保存工件:
build_repo:
stage: build
script:
- your script
artifacts:
when: always
paths:
- public
因此它们将被传递到下一阶段 deploy
并且 pages
作业可以看到它们。