Master GitLab CI/CD: From Basics to Automated Deployments
This guide explains GitLab CI/CD fundamentals, including continuous integration, delivery, deployment, .gitlab-ci.yml configuration, runner setup, pipeline stages, Auto DevOps, and Kubernetes deployment, with practical code examples and visual walkthroughs for automating software delivery.
GitLab CI/CD Overview
GitLab CI/CD is an integrated tool in GitLab that enables Continuous Integration (CI), Continuous Delivery (CD), and Continuous Deployment (CD) to automate building, testing, and deploying applications.
How CI Works
Developers push small code changes to a Git repository; each push triggers scripts that build, test, and verify the code before merging into the main branch.
Continuous Delivery and Deployment
These extend CI by automatically deploying the application to production whenever changes are pushed to the default branch.
Configuration with .gitlab-ci.yml
The pipeline is defined in a .gitlab-ci.yml file placed at the repository root. GitLab Runner executes the scripts specified in this file.
before_script:
- apt-get install rubygems ruby-dev -y
run-test:
script:
- ruby --version 6Jobs are grouped into a pipeline; the example above installs dependencies and prints the Ruby version.
Pipeline Execution
When the .gitlab-ci.yml file is present, GitLab detects it and runs the defined jobs using a GitLab Runner, which can be a VM, physical machine, Docker container, or a cluster.
Runner Configuration
Runners communicate with GitLab via API; you can view or add runners under Settings → CI/CD .
Basic CI/CD Workflow
Push code to a branch → pipeline triggers.
Run automated scripts (build, test, review apps).
Merge feature branch to default branch → optional automatic deployment.
Rollback if issues arise.
CI/CD Stages
Verify : build, test, code quality, performance testing, container scanning, etc.
Package : store Docker images, NPM packages, Maven artifacts, Conan packages.
Release : continuous deployment, manual delivery, GitLab Pages, canary deployments, feature flags, releases, deploy boards, auto deploy to Kubernetes.
Auto DevOps
Auto DevOps provides predefined CI/CD configurations to automatically detect, build, test, deploy, and monitor applications, simplifying the full software lifecycle.
Kubernetes Deployment Example
Using GitLab’s native Kubernetes integration, you can create a project from a template, add a Kubernetes cluster, enable Auto DevOps, and deploy 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:
- masterViewing Pipelines and Jobs
After configuring the runner, you can monitor pipeline status under CI/CD → Pipelines and view individual job logs under Pipelines → Jobs .
Conclusion
Define the .gitlab-ci.yml file, push it to the repository, and configure a runner to automate building, testing, and deploying your application, optionally leveraging Auto DevOps for a streamlined DevOps workflow.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
