Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 384
Dave Sag Avatar asked Apr 01 '19 05:04

Dave Sag


People also ask

Why is my GitLab pipeline failing?

It might be a security vulnerability The code in your most recent commit could be vulnerable, or a dependency could be at risk, either of which would trigger a failed security test and thus a failed pipeline.

How do I find out why pipeline failed?

Get logs to diagnose problems You can view logs by navigating to the pipeline run summary and selecting the job and task. If a certain task is failing, check the logs for that task.

What is GitLab CI coordinator URL?

If you want to use Gitlab's CI(ci.gitlab.com), then your coordinator url is https://ci.gitlab.com/

Is CI CD free on GitLab?

If you have a public, open source project on GitHub you can now take advantage of free CI/CD on GitLab.com. As part of our commitment to open source, we offer all public projects our highest tier features (GitLab SaaS Ultimate) for free.


1 Answers

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
like image 108
slowko Avatar answered Sep 28 '22 09:09

slowko