Building a basic CI pipeline with GitLab

Christian Talavera
4 min readAug 8, 2021

A basic pipeline will be created on GitLab. The pipeline that will be created is called ‘pipeline-skateboarding’.

This is done by creating a new project that will be associated with the pipeline; this is done by navigating to Menu>Projects>Create new project>Create blank project:

Name the project slug pipeline-skateboarding and click "Create project".

This will be an empty repository; a new file representing the pipeline configuration file will need to be created:

This file will be named .gitlab-ci.yml, as the pipeline configuration is written in YAML:

The following block of code will be added; comments have been added to explain what each line’s function is:

# This is the GitLab CI/CD configuration file for this project.

# The 'stages' block defines each stage in the pipeline.
stages: # This block will have each pipeline stage nested in.
- build
- test

# This block will have represent the 'build' stage.
build:
stage: build # This explicitly defines the stage, 'build'.
script: # This contains nested commands to be run.
- echo 'Pipeline Stage - Building' # Display status message.
- mkdir build # Create a directory called "build".
- touch build/info.txt # Creates file "info.txt" in build/

# This block will represent the 'test' stage.
test:
stage: test # This explicitly defines the stage, 'test'.
script: # This contains nested commands to be run.
- echo 'Pipeline Stage - Testing' # Display status message.
- test -f 'build/info.txt' # This tests the created file.

The changes will need to be committed; the pipeline should start automatically.

** Be sure to add credit card information, as it is required by GitLab to prevent abuse **

Once this is done, pipeline minutes under the free usage plan are available to be used:

The old pipeline should be deleted; after being deleted, the .gitlab-ci.yml file should be committed again to auto-trigger the creation of another pipeline.

After this is done, the main repository should show that the pipeline is currently running:

After the pipeline finished, the “Build” stage passed, but the “Test” stage failed.

This is due to the created files in the “Build” stage just being discarded after the end of the stage’s execution.

For the “Build” and the “Test” stage to be linked together, an “artifact” will need to be created for the “Build” stage; the “Test” stage will then download the artifact so both jobs can communicate with each other.

The new YAML code with the created “artifact” is listed below:

# This is the GitLab CI/CD configuration file for this project.

# The 'stages' block defines each stage in the pipeline.
stages: # This block will have each pipeline stage nested in.
- build
- test

# This block will have represent the 'build' stage.
build:
stage: build # This explicitly defines the stage, 'build'.
script: # This contains nested commands to be run.
- echo 'Pipeline Stage - Building' # Display status message.
- mkdir build # Create a directory called "build".
- touch build/info.txt # Creates file "info.txt" in build/
artifacts:
paths:
- build/
# This block will represent the 'test' stage.
test:
stage: test # This explicitly defines the stage, 'test'.
script: # This contains nested commands to be run.
- echo 'Pipeline Stage - Testing' # Display status message.
- test -f 'build/info.txt' # This tests the created file.

After making the edits, commit the YAML config file and another pipeline should automatically execute:

The “Build” stage ran without error as expected:

Diving deep on the “Test” stage shows that the job was successful as well;

Notice in the logs that the artifacts were downloaded after updating the config file:

(project is hosted at: https://gitlab.com/ctalaveraw/pipeline-skateboarding)

--

--