Template

Node Release Pipeline

Install, lint, test, pack, and release a Node.js package with artifact reuse.

Best for npm libraries and frontend apps.

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "push"'
    - if: '$CI_COMMIT_BRANCH == "main"'

stages:
  - build
  - test
  - deploy

install:
  stage: build
  image: node:22-alpine
  script:
    - npm ci
  artifacts:
    paths:
      - node_modules/

lint:
  stage: test
  image: node:22-alpine
  needs:
    - job: install
      artifacts: true
  script:
    - npm run lint

deploy_preview:
  stage: deploy
  image: node:22-alpine
  needs:
    - lint
  rules:
    - if: '$CI_COMMIT_BRANCH != "main"'
      when: manual
  script:
    - npm run deploy:preview