I’m configuring a very simple CI job. GitLab Runner is running on my own server, the specific runner for this project has been registered, with the shell
executor, as I want to simply run shell commands.
stages:
- build
build:
stage: build
script:
- npm install
- npm run build
artifacts:
paths:
- "public/dist/main.js"
only:
- master
The job fails at the first command, npm install
, with npm: command not found
. I just installed npm
and node
via npm
. If I SSH on my server and run npm -v
, I can see version 8.5.5 is installed. If I sudo su gitlab-runner
, which I suppose is what GitLab Runner is running as, npm -v
works just as well.
I installed npm
while gitlab-runner
was already running. So I ran service gitlab-runner restart
, thinking that it had to reevaluate its PATH
, but it didn’t fix the issue.
I fixed it by simply adding this command before npm install
: . ~/.bashrc
.
I’m not sure why gitlab-runner didn’t properly read .bashrc
before, even though I restarted it. Maybe it’s not supposed to? That would be contrary to what’s said in the GitLab CI runners docs.
N.B.: A key element in me being able to debug this was to clone the repo on a folder on my server, cd into it, and run gitlab-runner exec shell build
after any (local) change to .gitlab-ci.yml
. Skipping the whole commit + push + wait was a huge time (and sanity) saver.