node.js - Gitlab-ci 没有使用我指定的 Node 版本

标签 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 并且我的测试失败,因为 Node 版本错误。

如何告诉 GitLab CI 使用 Node 10.15.3?

最佳答案

您没有标记您的作业,因此它可能在 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

我得到以下输出,这表明我们正在拉取正确的 Node 镜像版本:

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

关于node.js - Gitlab-ci 没有使用我指定的 Node 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55448489/

相关文章:

javascript - 如何仅接受来 self 的 API 服务器的 cookie

node.js - 带有命名参数的 `WHERE col IN`

GitLab SSH key 停止工作

java - 使用服务帐户部署多模块应用引擎项目

django - 检测 CI 中 Django 翻译 (PO) 文件的更改

maven - 如何为 docker shell gitlab runner 安装 maven

shell - 在 Gitlab CI 构建中,我无法通过私钥 ssh 进入 AWS EC2

node.js - 在 Intern 中调用 Chai 插件返回错误

node.js - 如何使用 Node.js 将对象数组正确转换为 CSV 文件?

python-3.x - 如何从 github 操作中运行 tox