← Каталог
GitLab CI — Production-скелет `.gitlab-ci.yml`
Фрагмент из «GitLab CI»: Production-скелет `.gitlab-ci.yml`.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
default:
image: node:20-alpine
interruptible: true
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
policy: pull-push
before_script:
- npm ci --prefer-offline
stages:
- validate
- test
- package
- deploy
lint:
stage: validate
script:
- npm run lint
unit:
stage: test
script:
- npm run test:unit
artifacts:
when: always
reports:
junit: reports/junit.xml
build:
stage: package
script:
- npm run build
artifacts:
paths:
- dist/
expire_in: 3 days
deploy_staging:
stage: deploy
needs: ["build"]
script:
- ./scripts/deploy-staging.sh
environment:
name: staging
url: https://staging.example.com
rules:
- if: $CI_COMMIT_BRANCH == "develop"
deploy_prod:
stage: deploy
needs: ["build"]
script:
- ./scripts/deploy-prod.sh
environment:
name: production
url: https://example.com
when: manual
rules:
- if: $CI_COMMIT_BRANCH == "main" workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH
- if: $CI_COMMIT_TAG
default:
image: node:20-alpine
interruptible: true
cache:
key:
files:
- package-lock.json
paths:
- node_modules/
policy: pull-push
before_script:
- npm ci --prefer-offline
stages:
- validate
- test
- package
- deploy
lint:
stage: validate
script:
- npm run lint
unit:
stage: test
script:
- npm run test:unit
artifacts:
when: always
reports:
junit: reports/junit.xml
build:
stage: package
script:
- npm run build
artifacts:
paths:
- dist/
expire_in: 3 days
deploy_staging:
stage: deploy
needs: ["build"]
script:
- ./scripts/deploy-staging.sh
environment:
name: staging
url: https://staging.example.com
rules:
- if: $CI_COMMIT_BRANCH == "develop"
deploy_prod:
stage: deploy
needs: ["build"]
script:
- ./scripts/deploy-prod.sh
environment:
name: production
url: https://example.com
when: manual
rules:
- if: $CI_COMMIT_BRANCH == "main"