Ada*_*hes 5 continuous-integration gitlab devops
考虑一个带有prebuild和build阶段的虚拟 gitlab 作业。
stages:
- prebuild
- build
Run Code Online (Sandbox Code Playgroud)
该阶段的唯一工作prebuild是为后续阶段创建和缓存依赖项。prebuild仅当 python 文件发生更改时才会触发该阶段requirements.txt。该build阶段有一个cache:policyof pull,这意味着它遵循prebuild缓存。例如,假设缓存由共享的单个文件组成sharedfile:
prebuild_job:
cache:
policy: pull-push
rules:
- changes:
- requirements.txt
paths:
- sharedfile
script:
- echo "FOOBAR" > sharedfile
build_job:
cache:
policy: pull
paths:
- sharedfile
script:
- cat sharedfile
Run Code Online (Sandbox Code Playgroud)
这就是我想要的——仅在更改并使用其输出prebuild时触发(在本例中但实际上是一个完整的 python 虚拟环境)。这非常有效,直到通过Clear Runner Caches按钮在 gitlab 上手动清除缓存,然后我们必须手动重新运行预构建步骤,否则构建将继续失败,因为预构建在缓存清除后从未重新触发。requirements.txtbuildsharedfile
我们如何设置规则或解决方法,以便prebuild_job除了现有的更改规则之外,如果缓存为空,也会触发?就像是
prebuild_job:
cache:
policy: pull-push
rules:
- changes:
- requirements.txt
- if: "$CACHE == {}" #<-- something like this
paths:
- sharedfile
script:
- echo "FOOBAR" > sharedfile
Run Code Online (Sandbox Code Playgroud)
可以添加一个可选按钮来手动重新触发预构建阶段。 allow_failure表示该按钮是可选的,不会阻止后续阶段。
prebuild_job:
cache:
policy: pull-push
rules:
- changes:
- requirements.txt
- if: '"True"'
when: manual
allow_failure: true
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
622 次 |
| 最近记录: |