π Exploring GitLab CI/CD β Stages, Jobs & Runners (Day 33)π οΈ

Table of contents
- π§ GitLab CI/CD Basics β Understanding Stages & Runners π’
- β What Youβll Learn Today:
- π What is GitLab CI/CD?
- π 1οΈβ£ Understanding GitLab CI/CD Components
- π 2οΈβ£ Understanding GitLab CI/CD Stages
- βοΈ 3οΈβ£ What Are GitLab Runners?
- π 4οΈβ£ Setting Up a GitLab CI/CD Pipeline
- π§ 5οΈβ£ Setting Up a GitLab Runner for Your Project
- π 6οΈβ£ Deploying Applications with GitLab CI/CD
- π 7οΈβ£ Best Practices for GitLab CI/CD
- π Final Thoughts β Why GitLab CI/CD Matters?

π§ GitLab CI/CD Basics β Understanding Stages & Runners π’
In IT, automation is the key to ensuring smooth software development and deployment. GitLab CI/CD provides a powerful way to automate building, testing, and deploying applications using pipelines.
π‘ Think of GitLab CI/CD as an airport security system π’βοΈ. Every passenger (code update) must go through multiple security checks (build & test stages) before boarding the plane (deployment).
β What Youβll Learn Today:
β What GitLab CI/CD is and why itβs important
β Understanding stages, jobs, and runners
β How to create a CI/CD pipeline in GitLab
β Running a real-world example pipeline
π What is GitLab CI/CD?
GitLab CI/CD is an automation tool that helps developers:
πΉ Automatically test and build applications when code is pushed
πΉ Ensure software quality before deployment
πΉ Deploy applications efficiently with fewer errors
β Challenges Without CI/CD:
Manual testing & deployments lead to delays and errors
Bugs go unnoticed until production, affecting users
Inconsistent environments make debugging difficult
β
With GitLab CI/CD:
β Every code update is automatically tested
β Builds and deployments are consistent across environments
β Developers get faster feedback on issues
π Real-World Analogy: CI/CD as a Fast-Food Kitchen ππ
The kitchen (CI/CD pipeline) follows a structured process
Orders (code updates) go through preparation (build) and quality checks (test)
If everything is good, they are delivered to customers (deployment)
π 1οΈβ£ Understanding GitLab CI/CD Components
GitLab CI/CD uses a .gitlab-ci.yml
file to define automation workflows. Letβs break down its key components:
Component | What It Does | Example π |
Pipeline | The complete CI/CD process | The entire fast-food preparation process |
Stages | Different phases in the pipeline | Cooking, Packing, Delivery |
Jobs | Tasks inside each stage | Grilling, Assembling, Packing |
Runners | Servers that execute jobs | Kitchen staff working on orders |
π 2οΈβ£ Understanding GitLab CI/CD Stages
A stage in GitLab CI/CD is a step in the pipeline, like build, test, or deploy.
π Example: CI/CD Stages for a Node.js App
stages:
- build
- test
- deploy
build_job:
stage: build
script:
- echo "Building the application..."
- npm install
test_job:
stage: test
script:
- echo "Running tests..."
- npm test
deploy_job:
stage: deploy
script:
- echo "Deploying to production..."
- ./deploy.sh
π― What Happens in Each Stage?
Stage | Purpose |
Build | Installs project dependencies |
Test | Runs unit and integration tests |
Deploy | Pushes the application to production |
π Real-World Analogy: Stages as an Automated Factory Process π
Build Stage = Raw materials are collected and assembled
Test Stage = Quality checks are performed
Deploy Stage = Finished products are sent to customers
βοΈ 3οΈβ£ What Are GitLab Runners?
Runners are servers that execute CI/CD pipeline jobs.
Runner Type | Description | Example |
Shared Runner | Managed by GitLab, used by multiple projects | Temporary contract workers in a factory |
Specific Runner | Dedicated to a single project | Full-time employees for a single department |
Group Runner | Shared across multiple projects in a GitLab group | Team members working across multiple departments |
π Real-World Analogy: Runners as Kitchen Staff π³
Shared Runners = Freelance chefs working on multiple restaurant orders
Specific Runners = Chefs dedicated to a single restaurant
Group Runners = Chefs preparing meals for multiple branches of a restaurant
π 4οΈβ£ Setting Up a GitLab CI/CD Pipeline
πΉ Step 1: Create a .gitlab-ci.yml
File
Inside your GitLab repository, create a new file:
.gitlab-ci.yml
πΉ Step 2: Define the Pipeline Stages
Copy and paste the following YAML configuration:
stages:
- build
- test
- deploy
build_app:
stage: build
script:
- echo "Building the application..."
- npm install
test_app:
stage: test
script:
- echo "Running tests..."
- npm test
deploy_app:
stage: deploy
script:
- echo "Deploying to production..."
- ./deploy.sh
π How It Works:
β Build Stage β Installs dependencies
β Test Stage β Runs unit tests
β Deploy Stage β Pushes the application to production
π§ 5οΈβ£ Setting Up a GitLab Runner for Your Project
πΉ Step 1: Install GitLab Runner
sudo apt update
sudo apt install gitlab-runner
πΉ Step 2: Register a New Runner
gitlab-runner register
π Youβll be prompted to enter:
β GitLab URL β Your GitLab instance URL
β Runner Token β Found under Settings > CI/CD > Runners
β Runner Type β Choose shell, docker, or Kubernetes
π Now, your GitLab Runner is ready to execute CI/CD jobs!
π 6οΈβ£ Deploying Applications with GitLab CI/CD
πΉ Deploying to AWS S3 (Static Website Hosting)
GitLab CI/CD can deploy static websites to AWS S3 automatically.
π Example Deployment Job:
deploy:
stage: deploy
script:
- aws s3 sync ./build s3://my-s3-bucket --delete
environment:
name: production
πΉ Deploying Docker Containers with GitLab CI/CD
Many IT teams deploy applications using Docker for better scalability.
π Example Deployment Job for Docker:
deploy:
stage: deploy
script:
- docker build -t my-app:latest .
- docker push my-dockerhub-user/my-app:latest
π 7οΈβ£ Best Practices for GitLab CI/CD
β
Use Caching β Speed up pipelines by caching dependencies
β
Run Tests Before Deployment β Catch bugs early
β
Use Secrets for Credentials β Never hardcode API keys
β
Monitor Pipeline Performance β Optimize execution time
β
Enable Rollbacks β Rollback strategies for failed deployments
π Final Thoughts β Why GitLab CI/CD Matters?
πΉ Automates software testing, building, and deployment
πΉ Reduces manual errors and speeds up releases
πΉ Improves software quality through standardized workflows
π Next Up: Advanced GitLab CI/CD β Multi-Stage Pipelines & Security Best Practices! π
π¬ Got questions? Drop them below! Letβs discuss! π
Subscribe to my newsletter
Read articles from SRITESH SURANJAN directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

SRITESH SURANJAN
SRITESH SURANJAN
π Passionate DevOps Engineer with expertise in cloud computing, CI/CD, and automation. Skilled in Linux, Docker, Kubernetes, Terraform, Ansible, and Jenkins. I specialize in building scalable, secure, and automated infrastructures, optimizing software delivery pipelines, and integrating DevSecOps practices. Always exploring new ways to enhance deployment workflows and bridge the gap between development and operations.