Pipeline
A GitLab CI/CD pipeline is an automated workflow that runs jobs to build, test, validate, package, and deploy an application.
Key Topics
- • Automated workflows
- • Continuous Integration
- • Continuous Delivery
- • Pipeline execution
Learn how to automate building, testing, packaging, and deploying applications with GitLab CI/CD pipelines,.gitlab-ci.yml, stages, jobs, runners, and automation rules.
GitLab CI/CD Pipeline
Source Code
Build Application
Run Tests
Create Artifacts
Deploy Application
Introduction
GitLab CI/CD is used to automate software development workflows, including building, testing, validating, packaging, and deploying applications.
A GitLab CI/CD pipeline is configured using a YAML file that defines the stages, jobs, scripts, and rules required to automate the software delivery process.
The pipeline configuration is typically stored in a file named.gitlab-ci.ymlat the root of the project repository.
Core Concepts
GitLab CI/CD uses pipelines, stages, jobs, runners, variables, and configuration rules to automate different parts of the software development lifecycle.
A GitLab CI/CD pipeline is an automated workflow that runs jobs to build, test, validate, package, and deploy an application.
Key Topics
The .gitlab-ci.yml file contains the configuration for your GitLab CI/CD pipeline, including stages, jobs, scripts, variables, and execution rules.
Key Topics
Stages organize jobs into logical phases such as build, test, and deploy. Jobs in later stages normally wait for earlier stages to complete successfully.
Key Topics
Jobs are individual units of work in a pipeline. A job can execute commands for building applications, running tests, creating artifacts, or deploying software.
Key Topics
GitLab CI/CD Architecture
Your application source code and CI/CD configuration are stored in a GitLab project repository.
A pipeline coordinates the stages and jobs required to automate your software delivery workflow.
A stage groups related jobs and helps define the overall execution flow of the pipeline.
A job contains the commands and configuration required to perform a specific automation task.
A GitLab Runner is responsible for executing CI/CD jobs in the configured execution environment.
Artifacts store files generated by jobs so they can be downloaded or used by later parts of the pipeline.
Pipeline as Code
The.gitlab-ci.ymlfile contains the instructions that define how GitLab CI/CD should run your automation workflow.
Inside this file, you can define stages, jobs, scripts, variables, artifacts, rules, dependencies, and other CI/CD configuration.
Keeping the pipeline configuration with the application source code allows teams to version, review, and maintain automation as part of the project.
Example Project Structure
my-project/ │ ├── src/ │ ├── package.json │ ├── README.md │ └── .gitlab-ci.yml
Your First Pipeline
This example creates a pipeline with three stages: build, test, and deploy.
Each job belongs to a stage and contains a script with the commands GitLab should execute.
Jobs in the same stage can run in parallel when suitable runners are available, while later stages normally wait for earlier stages to complete successfully.
.gitlab-ci.yml
stages:
- build
- test
- deploy
build-job:
stage: build
script:
- npm ci
- npm run build
test-job:
stage: test
script:
- npm test
deploy-job:
stage: deploy
script:
- echo "Deploying application"Pipeline Execution
A developer pushes code, creates a merge request, runs a scheduled pipeline, or manually triggers a pipeline.
GitLab reads the CI/CD configuration and creates the pipeline based on the defined stages and jobs.
An available GitLab Runner receives the job and prepares the execution environment.
The pipeline executes build commands, tests, validation, and other automated tasks.
Build output and other generated files can be stored as artifacts for later jobs or downloads.
After successful validation, the pipeline can deploy the application to the required environment.
Use Cases
GitLab CI/CD can automate many tasks throughout the application development and software delivery lifecycle.
Automatically build and test applications whenever developers push code to a repository.
Run unit tests, integration tests, linting, and other validation tasks automatically.
Compile applications and generate build artifacts through automated CI/CD jobs.
Build and manage container images as part of your GitLab CI/CD pipeline.
Deploy validated applications to development, staging, production, Kubernetes, cloud, or other environments.
Run recurring CI/CD pipelines for maintenance, testing, reporting, backups, and other automated tasks.
Learning Roadmap
Follow these steps to move from GitLab CI/CD fundamentals to building complete automated delivery pipelines.
Learn how GitLab projects, pipelines, stages, jobs, and runners work together.
Add a .gitlab-ci.yml file to your repository and create a simple job.
Organize your pipeline into stages such as build, test, and deploy, then define jobs inside those stages.
Understand how runners execute jobs and how execution environments are selected.
Configure environment variables and preserve generated files for later use in your pipeline.
Combine builds, testing, artifacts, containerization, and deployment into a complete automated workflow.
Best Practices
Store your .gitlab-ci.yml configuration in the project repository so pipeline changes can be versioned and reviewed.
Use descriptive names that make it easy to understand what each job does when viewing pipeline results.
Use GitLab CI/CD variables and appropriate security settings instead of storing passwords, tokens, or keys directly in your configuration.
Store important build output as artifacts when it is required by later jobs or needs to be downloaded.
Organize stages and job dependencies efficiently to reduce unnecessary waiting and improve pipeline execution time.
Monitor job logs, failures, artifacts, and pipeline history to identify and troubleshoot automation problems.
Continue Learning
Learn Continuous Integration, Continuous Delivery, pipelines, automated testing, and software delivery.
⚡Learn how to automate builds, testing, workflows, and deployments from your GitHub repository.
⚙️Learn Jenkins pipelines, Jenkinsfiles, stages, agents, jobs, testing, and CI/CD automation.
Next Step
Practice creating.gitlab-ci.ymlfiles, defining stages and jobs, using runners, managing artifacts, and building complete CI/CD automation workflows.