术语“CI=false”未被识别为 cmdlet、函数、脚本文件或可操作程序的名称

zhr*_*gci 5 node.js npm reactjs gitlab-ci gitlab-ci-runner

我正在尝试 gitlab 的 CI/CD 并正在制作一个构建项目的 yml 文件。问题是我得到以下信息:

$ npm run build
 > myreactapp@0.1.0 build C:\GitLab-Runner\builds\QLuLhspz\0\I416547\s4-software-fun-frontend
 > react-scripts build
 Creating an optimized production build...
 Treating warnings as errors because process.env.CI = true.
 Most CI servers set it automatically.
 Failed to compile.
 ./src/Components/Task/TaskList.js
   Line 120:15:  'currentTasks' is assigned a value but never used                                 no-unused-vars
   Line 175:25:  Headings must have content and the content must be accessible by a screen reader  jsx-a11y/heading-has-content
 ./src/Components/House/House.js
   Line 150:16:  'Address' is assigned a value but never used      no-unused-vars
   Line 150:25:  'HouseNumber' is assigned a value but never used  no-unused-vars
   Line 150:38:  'City' is assigned a value but never used         no-unused-vars
 ./src/Components/House/HouseList.js
   Line 160:25:  Headings must have content and the content must be accessible by a screen reader  jsx-a11y/heading-has-content
 ./src/Components/Person/PersonList.js
   Line 183:25:  Headings must have content and the content must be accessible by a screen reader  jsx-a11y/heading-has-content
 ./src/Components/Footer.js
   Line 2:28:  'Row' is defined but never used  no-unused-vars
 ./src/Components/Person/Person.js
   Line 4:9:     'Link' is defined but never used                  no-unused-vars
   Line 166:16:  'FullName' is assigned a value but never used     no-unused-vars
   Line 166:26:  'PhoneNumber' is assigned a value but never used  no-unused-vars
 npm ERR! code ELIFECYCLE
 npm ERR! errno 1
 npm ERR! myreactapp@0.1.0 build: `react-scripts build`
 npm ERR! Exit status 1
 npm ERR! 
 npm ERR! Failed at the myreactapp@0.1.0 build script.
 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
 npm ERR! A complete log of this run can be found in:
 npm ERR!     C:\WINDOWS\system32\config\systemprofile\AppData\Roaming\npm-cache\_logs\2020-05-17T11_42_43_915Z-debug.log
Uploading artifacts for failed job
00:00
 ERROR: Job failed: exit status 1
Run Code Online (Sandbox Code Playgroud)

现在它说警告设置为错误,所以我尝试在 yml 文件中添加CI=false

stages: ["build", "test", "deploy"]

before_script:
    - npm install
    - CI=false

build:
    stage: build
    script: npm run build

test:
    stage: test
    script: npm run test

deploy:
    stage: deploy
    script: npm run start
Run Code Online (Sandbox Code Playgroud)

但比它说的命令不被识别。是因为它不是一个powershell命令还是react.js使用了node-command?(无论哪种方式都不起作用)

尝试过的来源:

编辑:发现问题......而不是在 yml 文件中执行它,而应该在项目本身中完成。如何在React JS中设置环境变量..?

Lio*_*owe 2

您需要设置环境变量并运行每个相关命令:CI=false npm run buildCI=false npm run build

如果将其设置为before_script,GitLab CI 会尝试将其作为独立命令运行(实际上它只是设置一个环境变量)。

是因为它不是一个powershell命令还是react.js使用了node-command?

Powershell 仅适用于 Windows,而 GitLab CI 命令是在 Linux 上运行的 bash 命令。React 与 Node.js 无关,尽管 create-react-app 确实使用了它。设置的环境变量可以由任何代码读取,无论它是 Node.js 还是其他代码。