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

问题描述 投票:1回答:1

我对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?

node.js continuous-integration gitlab gitlab-ci
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.