Create a CI/CD Pipeline in Minutes With GitLab
Published: 2021-03-07 00:12:13

---
title: Create a CI/CD Pipeline in Minutes With GitLab
published: true
description: This tutorial describes how to create a simple CI/CD pipeline using GitLab.
tags: 
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yivzvackc9ioqkgfxsee.png
---
This article is a quick tutorial on creating a simple CI/CD pipeline in [GitLab](https://gitlab.com/).

## What is CI/CD?

_CI/CD_ stands for continuous **i**ntegration and **d**elivery/**d**eployment. It is a way to develop software in small, automated batch cycles with continuous builds, tests, and deployment. CI/CD is a fundamental concept in [DevOps](https://docs.gitlab.com/ee/ci/introduction/#a-deeper-look-into-the-cicd-workflow) environments. GitLab has built-in tools that make it easy to create CI/CD pipelines.

See the excellent GitLab CI/CD documentation [here](https://docs.gitlab.com/ee/ci/README.html).

## What you will need

* GitLab [account](https://gitlab.com/users/sign_up)
* Linux terminal, Mac Terminal app, or Windows [Git Bash](https://git-scm.com/download/win)
* Your software application

## Tutorial

#### 1. Version your software application. ####

Create a GitLab repo for your software application. Add your programs(s) to the repo. Here is a sample Python program for this CI/CD tutorial:

```python

# hello.py
print('Hello world.')

```

#### 2. Enable a GitLab Runner. ####

From a web browser, go to your GitLab repo. Go to **Settings > CI / CD > Runners > Shared runners**. Make sure _Enable shared runners for this project_ is checked.

#### 3. Create a `.gitlab-ci.yml` file. ####

Create a file named `.gitlab-ci.yml` in the top folder of your repo. The _YAML_ file defines the CI/CD pipeline:

```bash
image: python:latest

job0:
  stage: build
  script:
    - echo "build phase..."
    - uname -a

job1:
  stage: test
  script:
    - echo "test phase..."
    - python helloworld.py

job2:
  stage: deploy
  script:
    - echo "deploy phase..."
```

This `.gitlab-ci.yml` file defines a basic pipeline for the Python program. There are three basic stages: _build_, _test_, and _deploy_. Since this is a basic program, the phases are simple. More complicated software applications have more steps in the phases.

There is a wide selection of CI/CD image [templates](https://docs.gitlab.com/ee/ci/examples/#cicd-templates) available for different types of software applications. Define the `.gitlab-ci.yml` file to meet your needs.

#### 4. Commit and push the `.gitlab-ci.yml` to your repo. ####

When you commit the `.gitlab-ci.yml` to your repo, it triggers the CI/CD pipeline. In fact, *any* commit to your remote GitLab repo triggers the pipeline.

After you push the file(s) to your repo, open a web browser and go to your GitLab project. In the left sidebar, click **CI / CD > Pipelines**. This is where you view the pipeline:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/31212gj06wqbpbcxeqby.png)

View information about the pipeline as it executes. Here is a log file for the _test (job1)_ phase:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1f321imi2sikbh4ky4k.png)

This pipeline completes successfully, three green checkmarks:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibq5gaucjqi3zq741cot.png)

#### 5. Introduce an error in your program. ####

Modify the `helloworld.py` program and introduce an error to it. Commit and push the program to the repo. This breaks the pipeline:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x79eyyykzwbr3fddlk1f.png)

The bad program causes the pipeline to fail. The pipeline continuously integrates our software changes and provides feedback on whether or not it succeeds or fails. You see the status of the pipeline in the browser and receive emails for failed pipelines.

## What next?

This tutorial demonstrates how to build a basic CI/CD pipeline in GitLab. It is just a start. Build more advanced CI/CD pipelines to suit you needs.

Customize and expand the pipeline stages. For example, your web application may need additional build steps to load external modules. Your test phase may include automated unit tests or program linting. Your deploy phase may deploy the software to a production environment for customers.

This is just a start. Build your first CI/CD pipeline in GitLab and see how far you can take it!

Thanks for reading. 😃

*Follow me on Twitter [`@realEdwinTorres`](https://twitter.com/realEdwinTorres) for more programming tips and help.*