Top Tags

GitLab Pipeline Next.js Example

GitLab CI/CD pipeline example for Next.js

Example GitLab CI/CD pipeline for Next.js

This is a ready-to-use GitLab CI configuration for a typical Next.js project. The YAML block below is left unchanged — it shows a basic workflow with an installation step, a build step and a parallel job. Read the short notes after the example to understand each section and adapt it to your project.

yaml
1image: node:latest
2
3stages:
4 - install
5 - build
6 - parallel
7
8cache:
9 key: ${CI_COMMIT_REF_SLUG}
10 paths:
11 - node_modules/
12
13install-deps:
14 stage: install
15 script:
16 - npm install
17
18build-site:
19 stage: build
20 script:
21 - npm run build
22 dependencies:
23 - install-deps
24 artifacts:
25 paths:
26 - .next/
27 - out/ # include if you're using `next export`
28 expire_in: 1 hour
29
30parallel-job:
31 stage: parallel
32 script:
33 - echo "I'm running at the same time as build-site!"

Notes:

  • image: The base Node image used for jobs; change the tag to match your Node.js version.
  • stages: Defines the pipeline stages order (install → build → parallel).
  • cache: Speeds up npm installs by persisting node_modules between runs.
  • install-deps: Installs project dependencies (runs npm install).
  • build-site: Runs the Next.js build (npm run build), saves .next/ and out/ as artifacts for later jobs.
  • parallel-job: Example of a job that runs in the same pipeline stage as others (demonstrates parallelism).

Adapt the scripts, artifacts and cache to fit your repository layout and CI goals. Keep the YAML block above unchanged when copying into .gitlab-ci.yml.