Цель:
Правильно настроить этап сборки с учетом кипариса, расположенного в подпапке вместо root проекта / git. файл package.json
также не находится в root хранилища
Я использую следующую конфигурацию .gitlab-ci.yml:
# first, install Cypress, then run all tests (in parallel)
stages:
- build
- test
# to cache both npm modules and Cypress binary we use environment variables
# to point at the folders we can list as paths in "cache" job settings
variables:
npm_config_cache: "$CI_PROJECT_DIR/cypress-cast/.npm"
CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cypress-cast/cache/Cypress"
# cache using branch name
# https://gitlab.com/help/ci/caching/index.md
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- .npm
- cache/Cypress
- node_modules
# this job installs NPM dependencies and Cypress
install:
image: cypress/base:10
stage: build
script:
- npm ci
# check Cypress binary path and cached versions
# useful to make sure we are not carrying around old versions
- npx cypress cache path
- npx cypress cache list
- $(npm bin)/print-env CI
- npm run cy:verify
# all jobs that actually run tests can use the same definition
.job_template:
image: cypress/base:10
stage: test
script:
# print CI environment variables for reference
- $(npm bin)/print-env CI
# start the server in the background
- npm run start:ci &
# run Cypress test in load balancing mode
- npm run e2e:record -- --key 4efafe61-914a-46bb-8134-3f77c6100719 --parallel --group "electrons on GitLab CI"
artifacts:
when: always
paths:
- cypress/videos/
- cypress/screenshots/
# actual job definitions
# all steps are the same, they come from the template above
electrons-1:
extends: .job_template
electrons-2:
extends: .job_template
electrons-3:
extends: .job_template
electrons-4:
extends: .job_template
electrons-5:
extends: .job_template
Ошибка Gitlab CI Runner:
$ npm ci
npm ERR! path /builds/Cast-Soft/cypress-ci-test/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/builds/Cast-Soft/cypress-ci-test/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /builds/Cast-Soft/cypress-ci-test/cypress-cast/.npm/_logs/2020-04-08T18_31_07_337Z-debug.log
Running after_script
00:01
Uploading artifacts for failed job
00:02
ERROR: Job failed: exit code 1
Я знаю, что это проблема, поскольку Cypress не находится в папке root (включая пакет и cypress config), но внутри папки с именем cypress-cast, поэтому я добавил команду
cd $ CI_PROJECT_DIR / cypress-cast /
script:
- cd $CI_PROJECT_DIR/cypress-cast/
- npm ci
# check Cypress binary path and cached versions
# useful to make sure we are not carrying around old versions
- npx cypress cache path
- npx cypress cache list
- $(npm bin)/print-env CI
- npm run cy:verify
Новые проблемы
$ npm run start:ci &
$ npm run e2e:record -- --key xxxxxxxxxxxxxxxxxxxxx --parallel --group "electrons on GitLab CI"
npmnpm ERR! ERR!path /builds/Cast-Soft/cypress-ci-test/package.json
path /builds/Cast-Soft/cypress-ci-test/package.json
npm npm ERR! codeERR! code ENOENT
ENOENT
npmnpm ERR!ERR! errno errno -2
-2
npm ERR!npm ERR!syscall open
syscall open
npmnpm ERR!ERR! enoent enoent ENOENT: no such file or directory, open '/builds/Cast-Soft/cypress-ci-test/package.json'
ENOENT: no such file or directory, open '/builds/Cast-Soft/cypress-ci-test/package.json'
npmnpm ERR!ERR! enoentenoent This is related to npm not being able to find a file.
This is related to npm not being able to find a file.
npmnpm ERR!ERR! enoentenoent
npmnpm ERR! ERR! A complete log of this run can be found in:
A complete log of this run can be found in:
npm ERR!npm /builds/Cast-Soft/cypress-ci-test/cypress-cast/.npm/_logs/2020-04-08T21_52_03_800Z-debug.log
ERR! /builds/Cast-Soft/cypress-ci-test/cypress-cast/.npm/_logs/2020-04-08T21_52_03_802Z-debug.log
Running after_script
00:01
Uploading artifacts for failed job
00:01
Uploading artifacts...
WARNING: cypress/videos/: no matching files
WARNING: cypress/screenshots/: no matching files
ERROR: No files to upload
ERROR: Job failed: exit code 1
Похоже, использование CD создает снежный ком из новых проблем, я пробовал npm ci --path $ CI_PROJECT_DIR / cypress-cast / и некоторые варианты, но это не так т работа.
Вопрос:
Где и как вначале установить значение по умолчанию для кипарисного пути, чтобы он работал вместе на нескольких этапах, таких как сборка и тестирование?