GitLab CI/CD Pipelines Explained with a Fun Tiramisu Recipe

Ever wondered how to set up a GitLab CI/CD pipeline like a DevOps engineer? In this article, you’ll learn the basics and create a fun pipeline that cooks a delicious Tiramisu.

GitLab CI/CD Pipeline Tutorial for Beginners #

During a DevOps crash course, I’ve been called to teach how to setup a simple GitLab pipeline.

It wasn’t easy: the people who took part in that course, were from very different backgrounds: backend in PHP, frontend, people out of school at their first job employment… despite of this, I’ve talked to them about what a devops does, who is it, and how pipelines are important.

In this article, you are going to learn how to setup a simple toy pipeline, in order to experiment a little bit with GitLab runners.

I don’t care just gimme the recipe and I’ll figure out everything else!!! here it is

How to do it #

The first step is to have a GitLab account. You can sign up for a GitLab account here. I personally don’t use that much GitLab, but I will move provided my use cases fits GitLab.

Next, you should create a repository:

gitlab-pipeline-1.png

fill the blanks as you prefer

gitlab-pipeline-2.png

and click the blue button “create a project”

gitlab-pipeline-3.png

Runner, YAML, pipeline… what are you talking about? #

Now it’s time to write a small pipeline and set the runner.

Pipeline #

A pipeline is a group of steps (named “stages”) that include jobs, what we need to do in each stage.

To understand more this concept, imagine cooking a Tiramisu: you have to first prepare ingredients, then you have to assemble them, there is a cooling part and the final step is service. These all stages.

Jobs can be, in the stage of preparing ingredients: make some coffee, whip cream and sugar…

Stages and jobs together in a file, form a pipeline, that is given to a runner.

Runner #

A runner is a server, running Linux, that will take what you wrote in your pipeline and setup all the processes in order to accomplish what you told it.

For example, if we said “dear runner, compile our application (given a Dockerfile) and publish it on GitLab” it will exactly do this thing.

The way to communicate between us and the machine, is using a YAML file.

YAML #

A YAML file is a plain text file, with some instructions in there. YAML is a declarative language, meaning that we don’t have to write specific keywords in order to describe or achieve something in particular, rather than we focus more on the grammar of the language to reach our goals.

To learn YAML I strongly suggest this amazing website that will teach you in no time how to write some YAML.

Ok, how do I setup the runner? #

Left side of the menu, “build”, “pipelines”

gitlab-pipeline-4.png

Next, click on the “test template”

gitlab-pipeline-5.png

We will be in the pipeline editor: this will create a .gitlab-ci.yml file at the end of our edits.

gitlab-pipeline-6.png

Click “commit changes” at the end and wait for a pipeline running warning at the top of the page.

gitlab-pipeline-7.png

If you click on the link in blue, you will see something like this:

gitlab-pipeline-8.png

don’t worry if something doesn’t have a green tick, it will be a matter of time.

If everything goes well, everything’s will be marked in green.

gitlab-pipeline-9.png

This means that pipeline has succeeded.

I got it, now I want to write a toy pipeline that describes a Tiramisu recipe #

Here’s the YAML file to copy paste in the pipeline:

stages:
- prep
- assembly
- cooling
- serving

prepare_cream:
stage: prep
script:
- date +%H%M%S
- echo "I beat the egg yolks with the sugar"
- echo "I add the mascarpone"
- echo "I whip the cream and fold it in"

prepare_coffee:
stage: prep
script:
- date +%H%M%S
- echo "I prepare the coffee with the Moka pot (preferably a large one)"
- echo "I let the coffee cool"

prepare_ladyfingers:
stage: prep
script:
- date +%H%M%S
- echo "I prepare the ladyfingers"

soak_ladyfingers:
stage: assembly
script:
- date +%H%M%S
- echo "I dip the ladyfingers in cold coffee"

layer_layouts:
stage: assembly
script:
- date +%H%M%S
- echo "Arrange the ladyfingers in the pan"
- echo "Spread the mascarpone cream"
- echo "Repeat the layers until the pan is full"
- echo "Drizzle the surface with bitter coffee or chocolate"

chill_tiramisu:
stage: cooling
script:
- date +%H%M%S
- echo "I refrigerate the tiramisu for at least 4 hours"

serve_tiramisu:
stage: serving
script:
- date +%H%M%S
- echo "I get the set of plates"
- echo "I plate the tiramisu"
- echo "I serve it to my guests"
- echo ":)"
- echo "Measure blood sugar"

This is the recipe in Italian:

stages:
- preparazione_ingredienti
- assemblaggio
- raffreddamento
- servizio

prepara_crema:
  stage: preparazione_ingredienti
  script:
    - date +%H%M%S
    - echo "Monto i tuorli con lo zucchero"
    - echo "Aggiungo il mascarpone"
    - echo "Monto la panna e la incorporo"

prepara_caffe:
  stage: preparazione_ingredienti
  script:
    - date +%H%M%S
    - echo "Preparo il caffé con la Moka (meglio se grande)"
    - echo "Lascio raffreddare il caffè"

prepara_savoiardi:
  stage: preparazione_ingredienti
  script:
    - date +%H%M%S
    - echo "Preparo i savoiardi"

inzuppa_savoiardi:
  stage: assemblaggio
  script:
    - date +%H%M%S
    - echo "Inzuppo i savoiardi nel caffè freddo"

metti_strati:
  stage: assemblaggio
  script:
    - date +%H%M%S
    - echo "Disporre i savoiardi nella teglia"
    - echo "Stendere la creama al mascarpone"
    - echo "Ripetere gli strati fino a esaurire lo spazio nella teglia"
    - echo "Spolverare con caffè amaro o cioccolato in superficie"

raffredda_tiramisu:
  stage: raffreddamento
  script:
    - date +%H%M%S
    - echo "Metto il tiramisù in frigo per almeno 4 ore"

servi_tiramisu:
  stage: servizio
  script:
    - date +%H%M%S
    - echo "Prendo il set di piattini"
    - echo "Impiatto il tiramisù "
    - echo "Servo ai miei ospiti"
    - echo ":)"
    - echo "Misurare la glicemia"

Save it into your pipeline editor, commit and…?

Where Tiramisu? #

gitlab-pipeline-10.png

We have cooked a delicious tiramisu and learnt how the pipeline works! 🍰🍫☕️

Ending #

Thanks for your attention, I highly suggest to try it out this simple example to get started with GitLab runners and pipelines. This was a toy example, but many other awesome things can be done.

Try this pipeline in your own GitLab project and share your results by sending me an email!

NOTE: the line “date” in script part, is for echoing the date time when the job is executed. This is to figure out if the job execution is done in parallel or in sequence. Figure it out for yourself, which of the two ways.