Start building your first GitLab CI Pipeline in under 5 minutes

CI or Continuous Integration is a software development practice where automated tests and build are run.Developers push code changes every day, multiple times a day. For every push to the repository, you can create a set of scripts to build and test yo…


This content originally appeared on Level Up Coding - Medium and was authored by Kyle Le

CI or Continuous Integration is a software development practice where automated tests and build are run.

Developers push code changes every day, multiple times a day. For every push to the repository, you can create a set of scripts to build and test your application automatically. These scripts help decrease the chances that you introduce errors in your application.

Today I will write a straight-forward tutorial on how to write a GitLab CI for a front-end application that has 3 basic steps:

  • Install dependencies
  • Build packages
  • Run unit tests

First, let’s create .gitlab-ci.yml file and enter an image for the CI and the workflow

The image keyword is the name of the Docker image the Docker executor uses to run CI/CD jobs. In the tutorial, I set image to node:16 meaning the project will be run on node version 16.

And the workflow is to control when pipelines are created. I set the rules so the pipeline is only created when an user commits or create merge requests ( but not on main branch )

This is the rest of the .gitlab-ci.yml file. I will explain the cache part later. First we have to define 3 stages for our pipeline which are straight-forward.

For each stage, we have to define the stage and the and the script . If you are familiar with yarn , these are very easy to understand:

  • yarn is to install needed dependencies
  • yarn build is to build to project
  • yarn test:jest is my script to run jest with my flags

The interruptible allows users to interrupt the stage.
Okay we’re now done, let’s look at the pipeline if it runs correctly

Don’t bother the Vercel job if you don’t use Vercel.

Now to understand how the cache part above works, let’s look at the install_dependencies job

It takes almost 19 seconds to finish. But this is just the first time, by defining the cache for the node_modules

And this is the result after for later pipeline:

Under a second, that’s impressive right ? Don’t worry if you add new dependencies, the install-dependencies job will figure it out.

That’s just a basic tutorial on how to write a GitLab CI, you can add more jobs, more rules, or with another images, just find the best way to write your CI Pipeline, you can dig deeper with the docs


Start building your first GitLab CI Pipeline in under 5 minutes was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Kyle Le


Print Share Comment Cite Upload Translate Updates
APA

Kyle Le | Sciencx (2022-10-26T11:17:31+00:00) Start building your first GitLab CI Pipeline in under 5 minutes. Retrieved from https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/

MLA
" » Start building your first GitLab CI Pipeline in under 5 minutes." Kyle Le | Sciencx - Wednesday October 26, 2022, https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/
HARVARD
Kyle Le | Sciencx Wednesday October 26, 2022 » Start building your first GitLab CI Pipeline in under 5 minutes., viewed ,<https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/>
VANCOUVER
Kyle Le | Sciencx - » Start building your first GitLab CI Pipeline in under 5 minutes. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/
CHICAGO
" » Start building your first GitLab CI Pipeline in under 5 minutes." Kyle Le | Sciencx - Accessed . https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/
IEEE
" » Start building your first GitLab CI Pipeline in under 5 minutes." Kyle Le | Sciencx [Online]. Available: https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/. [Accessed: ]
rf:citation
» Start building your first GitLab CI Pipeline in under 5 minutes | Kyle Le | Sciencx | https://www.scien.cx/2022/10/26/start-building-your-first-gitlab-ci-pipeline-in-under-5-minutes/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.