Knowledge

GitHub Actions and GitLab CI for the same Node.js project: writing two pipelines side by side

Updated 2026-11-22 · Present

  • For the same Node.js project, we write a lint, test and build pipeline with two tools: .github/workflows/ci.yml and .gitlab-ci.yml.
  • The main difference: GitHub Actions is organised by jobs and ready-made actions, while GitLab CI is organised by stages and uses image for the runtime environment.
  • Both offer a cache keyed on the lock file and artifacts to pass the dist/ folder between jobs.

Goal

After this article you can write a complete CI pipeline on both GitHub Actions and GitLab CI for the same Node.js project, and see where the two tools are alike and where they differ. The concepts of artifact and cache were explained in the first article of this series (about pipeline stages, artifacts and cache).

Preparation

The examples use Node.js 22 and an Ubuntu 24.04 runner. Check action and image version numbers against the official documentation, because they are updated over time.

Steps

Steps

Step 1: the pipeline on GitHub Actions

Create the file .github/workflows/ci.yml:

name: ci

on:
  push:
    branches: [main]
  pull_request:

jobs:
  test:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run lint
      - run: npm test

  build:
    needs: test
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
      - run: npm ci
      - run: npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: dist
          path: dist/
          retention-days: 7

Reading it part by part:

Step 2: the pipeline on GitLab CI

Create the file .gitlab-ci.yml at the root of the repository:

image: node:22

stages:
  - test
  - build

default:
  cache:
    key:
      files:
        - package-lock.json
    paths:
      - .npm/

before_script:
  - npm ci --cache .npm --prefer-offline

test:
  stage: test
  script:
    - npm run lint
    - npm test

build:
  stage: build
  script:
    - npm run build
  artifacts:
    paths:
      - dist/
    expire_in: 1 week

Reading it part by part:

Step 3: run it and add conditions

Push the files to the repository. GitHub shows the result in the Actions tab, GitLab in the Build, Pipelines section (menu names may vary between versions). To limit a job to the default branch, GitLab uses rules:

build:
  stage: build
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  script:
    - npm run build

On GitHub, you add if: github.ref == 'refs/heads/main' to the relevant job.

Quick comparison

Item GitHub Actions GitLab CI
Configuration file .github/workflows/*.yml (several files) .gitlab-ci.yml (one root file)
Main unit job, with dependencies via needs stage containing jobs
Runtime environment runs-on plus setup actions image per job
Reuse actions from the marketplace include, templates
Cache actions/cache or the cache option of a setup action cache block with key, paths
Artifact actions/upload-artifact artifacts block

Neither tool is absolutely "better": choose based on where you already keep your code.

Verification

Common errors

References