GitLab 运行程序不携带 node_modules 并缓存到下一个作业?

如何解决GitLab 运行程序不携带 node_modules 并缓存到下一个作业?

我遇到了一个问题,即我的 e2e 测试在 GitLab 中失败但正常通过。我将问题缩小到 node_modules 并且 cypress 缓存没有延续到下一个工作。这就是出现 WARN Local package.json exists,but node_modules missing,did you mean to install 错误的原因,因为 node_modules 不存在。

我认为缓存没有结转的原因是因为它被保存在一个运行器上,但如果下一个工作在另一个运行器上,缓存将不存在并且最终会失败。我可以把所有东西都放在一个作业中,但如果我要添加另一个用于部署的作业,那么我仍然会遇到同样的问题。

这是我的 gitlab-ci.yml 文件:

image: cypress/base:12.18.4

variables:
  NPM_REGISTRY: https://registry.npmjs.org/
  npm_config_cache: $CI_PROJECT_DIR/.npm
  CYPRESS_CACHE_FOLDER: $CI_PROJECT_DIR/cache/Cypress

stages:
  - build
  - test:unit
  - test:e2e
  - lint

cache:
  key: ${CI_COMMIT_REF_SLUG}
  paths:
    - cache/Cypress
    - node_modules/

build:
  stage: build
  script:
    # set the npm registry if different from the default
    - npm config set registry $NPM_REGISTRY
    - npm i
    - npx cypress verify

test:unit:
  stage: test:unit
  script:
    - npm run test:unit:coverage
  artifacts:
    paths:
      - tests/unit/out/coverage
    when: always
    expire_in: 1 hour

test:e2e:
  stage: test:e2e
  script:
    - npm run test:e2e:headless
  artifacts:
    paths:
      - tests/e2e/out/reports
      - tests/e2e/out/coverage
    when: always
    expire_in: 1 hour

lint:
  stage: lint
  script:
    - npm run lint

这是 GitLab 中的错误日志:

Restoring cache
00:01
Updating CA certificates...
Checking cache for fix-gitlab-pipeline...
No URL provided,cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
Executing "step_script" stage of the job script
00:01
$ npm run test:e2e:headless
> start-test serve:e2e 8089 'cypress run'
sh: 1: start-test: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! rds@0.1.0 test:e2e:headless: `start-test serve:e2e 8089 'cypress run'`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the test@0.1.0 test:e2e:headless script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists,did you mean to install?
npm ERR! A complete log of this run can be found in:
npm ERR!     /builds/test/.npm/_logs/2021-01-05T17_16_55_957Z-debug.log
Uploading artifacts for failed job
00:00
Updating CA certificates...
WARNING: ca-certificates.crt does not contain exactly one certificate or CRL: skipping
WARNING: ca-cert-ca.pem does not contain exactly one certificate or CRL: skipping
Uploading artifacts...
WARNING: tests/e2e/out/reports: no matching files  
WARNING: tests/e2e/out/coverage: no matching files 
ERROR: No files to upload                          
ERROR: Job failed: exit code 1

解决方法

我在这里回答了一个类似的问题:https://stackoverflow.com/a/65798418/2307873

要点是默认情况下,每个运行程序都在该运行程序的文件系统上存储缓存的项目,因此其他运行程序将无法访问它。您可以配置它存储的路径,如果您的运行程序可以连接到共享文件系统,或者您可以使用 S3(或等效的 GC 或 Azure)或任何实现这些 API 的东西。我们使用实现 S3 API 的 Minio (https://min.io)。

gitlab 和 Minio 的文档在链接的答案中。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?