I needed a simple GitLab CI pipeline to run some tests on my project. It’s been a while since I’ve played with GitLab CI. Here’s some previous posts for future reference:
If you search for ‘gitlab’ I have a few more specific posts on GitLab and related topics, mainly from running my own GitLab server on my HomeLab.
To run my tests against a simple node project, I split the pipeline into 2 jobs, one to install my npm dependencies (and could also add other build related tasks here if needed), and then a test job. It’s worth noting that in order for the results of ‘npm install’ to preserve from the build job to the test job you need to preserve the cache and the node_modules dir as an artifact to be picked up by the following job:
build:
stage: build
image: node:22
script:
- npm install
cache:
paths:
- node_modules/
artifacts:
expire_in: 1 days
when: on_success
paths:
- node_modules/
test:
stage: test
image: node:22
script:
- npm test
This is following tips here.