Gitlab-ci没有使用我指定的节点版本

时间:2019-04-01 05:19:37

标签: node.js continuous-integration gitlab gitlab-ci

我是GitLab的新手,正在尝试为我的项目设置CI / CD系统。

我的.gitlab-ci.yml文件如下:

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

但是node -v行输出的是6.12.0而不是10.15.3,并且由于节点版本错误,我的测试失败了。

如何告诉GitLab CI使用Node 10.15.3?

1 个答案:

答案 0 :(得分:1)

您没有为作业添加标签,因此它可能是在shell-executor而不是docker-executor上运行。在工作说明中检查.dockerenv,以确保您在容器中运行;

给出这个简单的管道(基于您的管道):

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

我得到以下输出,这表明我们正在提取正确的节点映像版本:

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