How to use GitLab CI with Git

GitLab CI/CD provides integrated continuous integration and deployment pipelines directly in GitLab repositories, automating workflows based on Git events and repository activity. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented GitLab CI pipelines in enterprise projects throughout my 25 years of development experience. The most effective approach is creating a .gitlab-ci.yml file in the repository root that defines pipeline stages and jobs. This method enables automatic testing, building, and deployment on every Git push with parallel job execution and artifact management.

Create a .gitlab-ci.yml file in repository root to define CI/CD pipeline stages and jobs.

stages:
  - test
  - build
  - deploy

variables:
  NODE_VERSION: "20"

cache:
  paths:
    - node_modules/

test:
  stage: test
  image: node:${NODE_VERSION}
  script:
    - npm ci
    - npm run lint
    - npm test
  only:
    - merge_requests
    - main
    - develop

build:
  stage: build
  image: node:${NODE_VERSION}
  script:
    - npm ci
    - npm run build
  artifacts:
    paths:
      - dist/
    expire_in: 1 week
  only:
    - main
    - develop

deploy:
  stage: deploy
  image: node:${NODE_VERSION}
  script:
    - echo "Deploying application..."
    - npm run deploy
  only:
    - main
  when: manual

Here the stages section defines pipeline execution order: test runs first, then build, and finally deploy. The image specifies Docker images for job execution. The script section contains commands executed in each job. The cache configuration shares node_modules across pipeline runs for faster execution. The artifacts section saves build outputs, making them available for subsequent stages and downloads. The only keyword restricts jobs to specific branches, while when: manual requires manual approval for deployment.

Best Practice Note:

This is the GitLab CI configuration we use in CoreUI enterprise deployments for automated quality assurance and controlled releases. Use GitLab environments to track deployments across staging and production, implement review apps for merge requests to preview changes before merging, and leverage GitLab’s built-in container registry for Docker image management in deployment pipelines.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author