Gitlab-CI 避免对项目的反应部分进行不必要的重建
Gitlab-CI avoid unnecessary rebuilds of react portion of project
我的 CI 管道 (gitlab-ci) 中有一个阶段如下:
build_node:
stage: Build Prerequisites
only:
- staging
- production
- ci
image: node:15.5.0
artifacts:
paths:
- http
cache:
key: "node_modules"
paths:
- ui/node_modules
script:
- cd ui
- yarn install --network-timeout 600000
- CI=false yarn build
- mv build ../http
然而,UI 并不是该项目的唯一部分。还有其他文件有自己的构建过程。因此,每当我们仅提交对那些其他文件的更改时,这个阶段每次都会重新运行,即使 ui
文件夹中没有任何更改。
有没有办法让 gitlab 缓存或者如果没有变化就不用每次都重建它?应触发重建的任何更改都将在 ui
文件夹下。如果可能,让它使用旧版本?
可以使用 rules:changes
关键字在最新的 Gitlab 版本中执行此操作。
rules:
- changes:
- ui/*
Link: https://docs.gitlab.com/ee/ci/jobs/job_control.html#variables-in-ruleschanges
这只会检查 ui
文件夹内的更改并触发此阶段。
查看此 link 了解更多信息:https://docs.gitlab.com/ee/ci/yaml/#ruleschanges
我的 CI 管道 (gitlab-ci) 中有一个阶段如下:
build_node:
stage: Build Prerequisites
only:
- staging
- production
- ci
image: node:15.5.0
artifacts:
paths:
- http
cache:
key: "node_modules"
paths:
- ui/node_modules
script:
- cd ui
- yarn install --network-timeout 600000
- CI=false yarn build
- mv build ../http
然而,UI 并不是该项目的唯一部分。还有其他文件有自己的构建过程。因此,每当我们仅提交对那些其他文件的更改时,这个阶段每次都会重新运行,即使 ui
文件夹中没有任何更改。
有没有办法让 gitlab 缓存或者如果没有变化就不用每次都重建它?应触发重建的任何更改都将在 ui
文件夹下。如果可能,让它使用旧版本?
可以使用 rules:changes
关键字在最新的 Gitlab 版本中执行此操作。
rules:
- changes:
- ui/*
Link: https://docs.gitlab.com/ee/ci/jobs/job_control.html#variables-in-ruleschanges
这只会检查 ui
文件夹内的更改并触发此阶段。
查看此 link 了解更多信息:https://docs.gitlab.com/ee/ci/yaml/#ruleschanges