我正在尝试为单声道存储库设置GitLab CI。
为了论证的缘故,我们可以说我想处理2个JavaScript包:
应用 CLI我已经定义了3个阶段:
安装 测试 建立 部署因为我正在重复使用之前步骤中的文件,所以我使用了GitLab缓存。
我的配置如下所示:
stages: - install - test - build - deploy install_app: stage: install image: node:8.9 cache: policy: push paths: - app/node_modules script: - cd app - npm install install_cli: stage: install image: node:8.9 cache: policy: push paths: - cli/node_modules script: - cd cli - npm install test_app: image: node:8.9 cache: policy: pull paths: - app/node_modules script: - cd app - npm test test_cli: image: node:8.9 cache: policy: pull paths: - cli/node_modules script: - cd cli - npm test build_app: stage: build image: node:8.9 cache: paths: - app/node_modules - app/build script: - cd app - npm run build deploy_app: stage: deploy image: registry.gitlab.com/my/gcloud/image only: - master environment: name: staging url: https://example.com cache: policy: pull paths: - app/build script: - gcloud app deploy app/build/app.yaml --verbosity info --version master --promote --stop-previous-version --quiet --project "$GOOGLE_CLOUD_PROJECT"问题在于测试阶段。 大多数情况下, test_app作业失败,因为app/node_modules目录缺失。 有时候重试会起作用,但大多数情况下不会。
另外,我想为build_app作业使用两个缓存。 我想拉app/node_modules并推送app/build 。 我无法找到一种方法来实现这一点。 这让我觉得我没有完全理解缓存的工作原理。
为什么我的缓存文件没有了? 我误解了GitLab CI缓存的工作原理吗?
I'm trying to setup GitLab CI for a mono repository.
For the sake of the argument, lets say I want to process 2 JavaScript packages:
app cliI have defined 3 stages:
install test build deployBecause I'm reusing the files from previous steps, I use the GitLab cache.
My configuration looks like this:
stages: - install - test - build - deploy install_app: stage: install image: node:8.9 cache: policy: push paths: - app/node_modules script: - cd app - npm install install_cli: stage: install image: node:8.9 cache: policy: push paths: - cli/node_modules script: - cd cli - npm install test_app: image: node:8.9 cache: policy: pull paths: - app/node_modules script: - cd app - npm test test_cli: image: node:8.9 cache: policy: pull paths: - cli/node_modules script: - cd cli - npm test build_app: stage: build image: node:8.9 cache: paths: - app/node_modules - app/build script: - cd app - npm run build deploy_app: stage: deploy image: registry.gitlab.com/my/gcloud/image only: - master environment: name: staging url: https://example.com cache: policy: pull paths: - app/build script: - gcloud app deploy app/build/app.yaml --verbosity info --version master --promote --stop-previous-version --quiet --project "$GOOGLE_CLOUD_PROJECT"The problem is in the test stage. Most of the time the test_app job fails, because the app/node_modules directory is missing. Sometimes a retry works, but mostly not.
Also, I would like to use two caches for the build_app job. I want to pull app/node_modules and push app/build. I can't find a way to accomplish this. This makes me feel like I don't fully understand how the cache works.
Why are my cache files gone? Do I misunderstand how GitLab CI cache works?
最满意答案
缓存是尽力而为的,所以不要指望缓存会一直存在。
如果您在作业之间有很强的依赖性,请使用工件和依赖项 。
无论如何,如果只是为了node_modules ,我建议你在每一步都安装它,而不是使用工件 - 你不会在工件上节省很多时间。
The cache is provided on a best-effort basis, so don't expect that the cache will be always present.
If you have hard dependencies between jobs, use artifacts and dependencies.
Anyway, if it is just for node_modules, I suggest you to install it in every step, instead of using artifacts - you will not save much time with artifacts.
更多推荐
发布评论