Gitlab CI 在 Windows 上的 shell 仅在 before_script 运行

4
我的CI运行程序只能运行一行代码。我试图在运行eslint之前运行npm install。如果将npm install添加到before_script部分,则只会运行npm install,构建报告成功,而实际上根本没有运行eslint。多个命令在windows shell运行程序上不受支持吗?
我还尝试将npm install移到lint作业中,但结果相同。
我已在Windows主机上安装了GitLab多运行程序。这是我的.gitlab-ci.yml文件。
before_script:
  - npm install

stages:
  - test

cache:
  key: "$CI_BUILD_REF_NAME"
  paths:
    - node_modules/

lint:
  stage: test
  tags:
    - javascript
  script:
    - eslint **/*.js
2个回答

2

解决方案

您需要在 .gitlab-ci.yml 文件中任何 npm 命令前添加 "call"

before_script:
  - 'call npm install'

当使用Windows shell runner时,所有npm命令都需要执行。

解释

npm是一个shell脚本。因此,您必须添加call来在子shell中执行此脚本。否则,npm脚本中的“exit”命令会关闭由gitlab启动的shell。

请参见https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/issues/1025


0

这是在Windows上使用cmd.exe默认shell的问题。将其更改为Powershell似乎可以解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接