actual photo of the internals of gitlab ci pipeline
actual photo of the internals of gitlab ci pipeline

Image: Miguel Á. Padriñán

Getting started with gitlab-ci.yml

Tags: gitlab, software development, automation, continuous integration

October 10, 2018

Prerequisite Steps

Before attempting to use gitlab.yml, a few things must be in place:

  • GitLab instance
  • GitLab runner registered to the instance
  • you are a 'maintainer' for the project you want to setup

Before you start, I recommend watching this video or at least the beginning:

How to create the CI script

You'll want to clone a simple project in a tech stack that you're already familiar with. I will use a node.js app to demonstrate.

Because we build this app using the npm build command, which is used by the gitlab.yml script so that CI will build the same way. Essentially, if Gitlab CI can't build successfully (ie. if it hits any errors) then you will be notified and not be able to proceed with the MR until errors are rectified.

gitlab.yaml

This is a great way to get a simple automatic feedback mechanism you can use to speed up development. The most basic gitlab.yml file for a node.js project could be super simple:


    image: node:14.2.2

    dependencies:
      script:
      - npm install

    build:
      script
      - npm run build

Caching node_modules

Optionally, speed things up by adding the cache paths to node_modules folder.


    image: node:14.2.2
    cache:
      paths:
      - node_modules/

    dependencies:
      script:
      - npm install

    build:
      script
      - npm run build

How to use the automated pipeline

Great, now you have a pipeline in place. This code is essentially waiting for some trigger. Let's look at how we trigger and use the automation we've created.

Trigger the Pipeline

All you need to do is add a commit that puts this new file, gitlab.yml, in the root directory of your project. GitLab will now create a pipeline and tell you the result.

Hopefully, this helps you to leverage the power of automation.

References

Conclusion

I hope this helps you to leverage the power of automation. Gitlab CI is a great capability to have in your toolbox. It's a great way to get a simple automatic feedback mechanism you can use to speed up development.


Loading...

© Copyright 2023 Nathan Phennel