Automating GitLab CI/CD for Main Branch Commits in Specific Directories

Problem to solve

GitLab does not run my CI/CD automatically. The CI/CD should run automatically upon a commit to the main branch if any files in the content/* directory have changed.

Manual building works fine.

Configuration

Here is my .gitlab-ci.yml

stages:
  - build
  - deploy
 
variables:
  NODE_VERSION: "18.14"
 
build:
  stage: build
  rules:
    - if: '$CI_COMMIT_REF_NAME == "main"'
      changes:
        - content/*
  
  before_script:
    - apt-get update -q && apt-get install -y nodejs npm
    - npm install -g n
    - n $NODE_VERSION
    - hash -r
    - npm ci
  script:
    - npx quartz build
  artifacts:
    paths:
      - public
  cache:
    paths:
      - ~/.npm/
    key: "${CI_COMMIT_REF_SLUG}-node-${CI_COMMIT_REF_NAME}"
 
pages:
  stage: deploy
  rules:
    - if: '$CI_COMMIT_REF_NAME == "main"'
      changes: []  # Run regardless of changes
        
  script:
    - echo "Deploying to GitLab Pages..."
  artifacts:
    paths:
      - public

Versions

Please select whether options apply, and add the version information.
[ x ] GitLab.com SaaS free version