Dave Sag
Dave Sag

Reputation: 13486

Gitlab-ci is not using the node version I have specified

I'm very new to GitLab and am trying to set up the CI/CD system for my project.

My .gitlab-ci.yml file is as follows:

image: node:10.15.3

cache:
  paths:
  - node_modules/

before_script:
  - node -v
  - npm install

stages:
  - test

all-tests:
  stage: test
  script:
    - npm run lint
    - npm run test:unit:cov
    - npm run test:server

However the node -v line outputs 6.12.0 not 10.15.3 and my tests are failing because the node version is wrong.

How do I tell GitLab CI to use Node 10.15.3?

Upvotes: 12

Views: 31503

Answers (1)

slowko
slowko

Reputation: 875

You are not tagging your job so perhaps it is running on a shell-executor and not a docker-executor. Check for .dockerenv in your job spec to ensure you're running in a container;

Given this simple pipeline (based on yours):

image: node:10.15.3

before_script:
  - node -v

stages:
  - test

all-tests:
  tags:
    - docker
  stage: test
  script:
    # are we in a docker-executor
    - if [ -f /.dockerenv ]; then echo "docker-executor"; fi

I get the following output, which suggests we are pulling the correct node image version:

Running with gitlab-runner 11.3.1 (0aa5179e)
  on gitlab-docker-runner fdcd6979
Using Docker executor with image node:10.15.3 ...
Pulling docker image node:10.15.3 ...
Using docker image sha256:64c810caf95adbe21b5f41be687aa77aaebc197aa92f2b2283da5d57269d2b92 for node:10.15.3 ...
Running on runner-fdcd6979-project-862-concurrent-0 via af166b7f5bef...
Fetching changes...
HEAD is now at b46bb77 output container id
From https://gitlab/siloko/node-test
   b46bb77..adab1e3  master     -> origin/master
Checking out adab1e31 as master...
Skipping Git submodules setup
$ node -v
v10.15.3
$ if [ -f /.dockerenv ]; then echo "docker-executor"; fi
docker-executor
Job succeeded

Upvotes: 6

Related Questions