How to Deploy a Static Site to GitLab Pages From CI
GitLab Pages publishes whatever a job named pages leaves in the public/ directory and declares as an artifact.
Create a job named pages, build your site into public/, and declare artifacts.paths: [public]. GitLab picks up the artifact and serves it as your Pages site.
Steps
- Name the deploy job exactly
pages. - Build the site so its output lands in
public/. - Declare
publicunderartifacts.paths. - Restrict the job to the default branch with
rules.
Pipeline
.gitlab-ci.yml
pages:
stage: deploy
image: node:20
script:
- npm ci
- npm run build
- mv dist public
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCHGotchas
- The output directory must be
public; any other name is ignored. - If your build already writes to
public, drop themvstep. - Set the framework base path to the project path when not using a custom domain.
Related guides
How to Deploy a Static Site to GitHub Pages From CIDeploy a built static site to GitHub Pages from GitHub Actions using actions/upload-pages-artifact and action…
How to Set the Base Path for a Static Site Deployed to a SubdirectoryConfigure the base path for a static site served from a subdirectory (like a project Pages URL) so asset and…