GitLab Logo

Creating an optimised GitLab pipline for eslint tests

Steps on how I created an optimised GitLab pipline for running eslint tests.

GitLab
Dependency Proxy
Pipeline

Published 1 year ago

1 minute read

The problem

When I initially started running these pipeline tests I was including node in my gitlab-ci file like this: image: node:latest. Doing this it was fetching and downloading the docker image for node everytime this test ran. It would take 3-4 minutes, far too long.

The aim

Cache the images and use locally on the GitLab instance, in order to run eslint and other tests efficiently.

1 - Enable Depedency Proxy

"The GitLab Dependency Proxy is a local proxy you can use for your frequently-accessed upstream images.

In the case of CI/CD, the Dependency Proxy receives a request and returns the upstream image from a registry, acting as a pull-through cache"

GitLab details the instructions on how to do enable this here.

2 - Create your gitlab-ci.yml

Read more on the CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX here.

# image: node:latest - Replaced by below image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/node:latest stages: - lint eslint: stage: lint cache: key: files: - package-lock.json paths: - node_modules script: # Install ESLint in this docker container - npm install # Run ESLint - npm run test

3 - Edit your package.json

The pipeline is installing the package from the repository and running the npm script test.

"scripts": { ... "test": "eslint . --ext .js,.jsx,.ts,.tsx", // Run from the pipeline },

4 - Tests will now run

When all changes are saved you should see your pipeline running. eslint tests successful

As part of merge requests you will now also see the pipeline running. If tests fail for whatever reason, you will see this. eslint tests fail