GitLab CI/CD: Architecting, Deploying, and Optimizing Pipelines

Architecture Core Concepts

Create and Run a Basic Pipeline

In this guide, you’ll learn how to set up a simple CI/CD pipeline on GitLab. We’ll walk through:

  1. Creating a GitLab Group
  2. Initializing a GitLab Project
  3. Configuring your .gitlab-ci.yml file
  4. Reviewing pipeline execution

By the end, you’ll have a working pipeline that builds, tests, and deploys automatically.

1. Create a GitLab Group

First, organize your demos under a top-level group called demos-group:

  1. Go to Groups → Create group.
  2. Set Group name to demos-group.
    The Group URL will be gitlab.com/demos-group.
  3. Choose Visibility Level: Public.
  4. Click Create group.

The image shows a GitLab interface for creating a new top-level group, with fields for group name, URL, and visibility settings. A warning message indicates that the group name should not contain a period for SCIM integration.

Once created, you’ll see the group dashboard:

The image shows a GitLab interface where a group named "demos-group" has been successfully created. It offers options to create a new subgroup or a new project.

Note

Group names should avoid special characters (e.g., periods) if you plan to integrate with SCIM or other identity providers.

2. Create a New Project

Inside demos-group, create a project named hello-world:

  1. Click New project → Create blank project.
  2. Enter Project name: hello-world
    The Project URL becomes gitlab.com/demos-group/hello-world.
  3. Set Visibility: Public.
  4. Check Initialize repository with a README.
  5. Click Create project.

The image shows a GitLab interface for creating a blank project, with fields for project name, URL, and visibility settings. Options for initializing a repository with a README and enabling security testing are also visible.

Your project page will display the README and initial instructions:

The image shows a GitLab project page for a "Hello World" repository. It includes details like the initial commit, project information, and a README file.

If you already have local code, push it with:

git remote add origin https://gitlab.com/demos-group/hello-world.git
git branch -M main
git push -uf origin main

3. Set Up CI/CD Pipeline

Click CI/CD → Pipelines → Setup CI/CD (or Configure pipeline) to open the editor. You’ll see a list of templates and an empty .gitlab-ci.yml file:

The image shows a GitLab interface with a focus on the Pipeline Editor, suggesting the creation of a CI/CD pipeline by configuring a `.gitlab-ci.yml` file. The sidebar displays project navigation options like "Plan" and "Code."

Browse available templates:

The image shows a GitLab interface with a list of CI/CD templates for various programming languages and frameworks, such as Android, Bash, and C++. Each entry has a "Use template" button.

If you leave the file empty, GitLab shows an error:

The image shows a GitLab Pipeline Editor with an invalid CI configuration error message, indicating that a job configuration is missing a script or trigger keyword.

Define a Minimal Pipeline

Add the following to .gitlab-ci.yml at the repository root:

stages:
  - build
  - test
  - deploy

first_job:
  stage: build
  script:
    - echo "This is our first GitLab CI Job"
    - ls
    - cat README.md

Commit directly to main. This push triggers a pipeline run automatically.

Pipeline Stages Overview

StagePurpose
buildCompile or prepare artifacts
testRun unit tests and code validation
deployDeploy to staging or production environment

4. Inspect the Repository and Pipeline

Back in Code → Files, confirm README.md and .gitlab-ci.yml are present:

The image shows a GitLab repository interface with a file list and a README.md file open, displaying instructions for getting started with GitLab.

Then navigate to CI/CD → Pipelines. You’ll see your new pipeline with a Passed status once it finishes:

The image shows a GitLab pipeline interface with a "Passed" status for a recent update to a `.gitlab-ci.yml` file. The sidebar includes options like Issues, Merge requests, and Pipelines.

Click the pipeline ID to drill into stages and jobs. Selecting first_job reveals the full log:

The image shows a GitLab interface displaying a job log for a project named "Hello World." The job has succeeded, and details such as duration, runner, and commit information are visible.

Sample Job Output

$ echo "This is our first GitLab CI Job"
This is our first GitLab CI Job
$ ls
README.md
$ cat README.md
## Hello World
## Getting started
To make it easy for you to get started with GitLab...

GitLab Shared Runners automatically provision a Docker container, fetch your code, run the script commands, then clean up after success.

Next Steps

In the following lessons, we’ll explore:

  • Advanced pipeline configurations
  • Caching and artifacts
  • Parallel and dynamic child pipelines

Watch Video

Watch video content

Previous
GitLab CI CD Core Components