Skip to main content

GitLab CI/CD Pipeline

Overview

This project demonstrates a production-ready CI/CD pipeline built with GitLab CI/CD, showcasing automated build, test, and deployment workflows. The pipeline implements industry best practices for continuous integration and continuous deployment, including Docker containerization, intelligent caching, artifact management, and automated testing with code coverage reporting.

Key Features

  • Three-Stage Pipeline: Build → Test → Deploy architecture
  • Docker Containers: Consistent environments using node:18 image
  • Intelligent Caching: Branch-specific caching with push/pull policies to optimize build times
  • Artifact Management: Build outputs passed between stages with configurable expiration
  • Code Coverage: Jest testing with Cobertura format integration into GitLab UI
  • GitLab Pages Deployment: Automated deployment to GitLab Pages
  • Branch Protection: Deploy only from main branch for production safety
  • Performance Monitoring: Cache verification and stage duration tracking

Pipeline Architecture

The pipeline follows a classic three-stage design pattern:

Build → Test → Deploy

Stage 1 (Build):
- Install dependencies
- Compile application
- Push cache (node_modules)
- Generate artifacts (public/)

Stage 2 (Test):
- Pull cache (node_modules)
- Run Jest tests
- Generate coverage reports
- Extract coverage metrics

Stage 3 (Deploy):
- Deploy to GitLab Pages
- Only on main branch
- Uses artifacts from build stage

CI/CD Best Practices

  • Docker Image Pinning: Uses specific versions (node:18) instead of latest for reproducibility
  • Cache Policy Optimization: Build stage pushes cache, test stage pulls only for faster execution
  • Fail Fast: Test stage runs quickly using cached dependencies
  • Artifact Expiration: Prevents storage bloat with appropriate expiration times
  • Branch Rules: Prevents accidental deployments with branch-specific job execution
  • Coverage Integration: Regex extraction integrates coverage percentages into GitLab's UI

Technologies Used

GitLab CI/CDDockerNode.jsJestDevOpsAutomationYAML

Learning Outcomes

This project demonstrates several advanced CI/CD concepts:

  • How to structure multi-stage pipelines for efficiency
  • When to use push vs pull cache policies
  • How to pass build artifacts between pipeline stages
  • How to integrate code coverage into GitLab's native UI
  • How to implement branch-based deployment strategies
  • How to monitor and optimize pipeline performance

Related Blog Post

For a detailed walkthrough of the pipeline architecture and design decisions, check out the companion blog post: Building CI/CD Pipelines with GitLab

Getting Started

Visit the GitLab repository to explore the .gitlab-ci.yml configuration, view pipeline execution logs, and see the code coverage reports.