Operations 12 min read

Mastering GitLab CI/CD: From Basics to Advanced Pipelines

This guide explains GitLab CI/CD concepts, configuration files, runner setup, pipeline stages, and advanced features like Auto DevOps, providing step‑by‑step examples and code snippets for practical implementation.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Mastering GitLab CI/CD: From Basics to Advanced Pipelines

GitLab CI/CD is an integrated tool in GitLab that enables continuous integration (CI), continuous delivery (CD), and continuous deployment. It works by pushing small code changes to a Git repository, automatically running scripts to build, test, and verify code before merging into the main branch.

Core Concepts

Continuous Integration: automatically builds and tests each change.

Continuous Delivery: extends CI by preparing deployments that can be manually triggered.

Continuous Deployment: fully automates deployment without manual steps.

The process is defined in a .gitlab-ci.yml file at the repository root, which GitLab Runner executes.

Basic Configuration

A simple pipeline consists of jobs grouped into stages (e.g., build, test, deploy). Example:

before_script:
  - apt-get install rubygems ruby-dev -y
run-test:
  script:
    - ruby --version 6

This defines a before_script to install dependencies and a

run-test</job> that prints the Ruby version. The pipeline runs on each push.</p>
<h2>Runner Setup</h2>
<p>Runners execute the jobs defined in <code>.gitlab-ci.yml

. They can be virtual machines, Docker containers, or physical machines and communicate with GitLab via API. After configuring a runner, you can view job status in the Pipelines > Jobs page.

Advanced Features

GitLab CI/CD supports visual pipelines, job logs, and rollback capabilities. It also integrates with Auto DevOps, which provides predefined CI/CD configurations for automatic detection, building, testing, deployment, and monitoring.

Auto DevOps can deploy projects to Kubernetes clusters (e.g., GKE) with minimal configuration, handling Helm, Ingress, and Prometheus setup automatically.

Typical CI/CD Workflow

Define .gitlab-ci.yml with jobs and scripts.

Push the file to the remote repository.

GitLab detects the file and triggers pipelines via the Runner.

Monitor pipeline stages (build → test → deploy → performance test) and view environments.

Use UI buttons to open the deployed app, view Prometheus metrics, or open a web terminal.

Example: Deploying a Spring Boot Application

image: "java:8"
stages:
  - build
  - deploy
before_script:
  - chmod +x mvnw
build:
  stage: build
  script:
    - ./mvnw package
  artifacts:
    paths:
      - target/demo-0.0.1-SNAPSHOT.jar
production:
  stage: deploy
  script:
    - curl --location "https://cli.run.pivotal.io/stable?release=linux64-binary&source=github" | tar zx
    - ./cf login -u $CF_USERNAME -p $CF_PASSWORD -a api.run.pivotal.io
    - ./cf push
  only:
    - master

This example defines a build stage that packages a Spring Boot JAR and a deployment stage that logs into Cloud Foundry and pushes the app.

Additional Capabilities

Auto DevOps for end‑to‑end pipelines.

Package management with Container Registry, NPM Registry, Maven Repository, and Conan Repository.

Release management, feature flags, canary deployments, and GitLab Pages.

Security testing reports and vulnerability scanning.

Overall, GitLab CI/CD provides a comprehensive, script‑driven workflow for automating software delivery from code commit to production deployment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ci/cdDevOpscontinuous integrationPipelineGitLab CI/CDRunnerAuto DevOps
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.