Gitlab CI 反应脚本:未找到

Har*_*rts 5 continuous-integration gitlab gitlab-ci devops

我正在尝试为示例反应项目构建一个简单的管道。这是我的 .gitlab-ci.yml 文件

image: node:12

stages:
  - build
  - test

build_react:
  stage: build
  script:
    - echo "Building deploy package"
    - yarn install
    - yarn build
    - echo "Build successful"
  artifacts:
    expire_in: 1 hour
    paths:
      - build

test_react:
  stage: test
  needs: [build_react]
  script:
    - echo "Testing project"
    - yarn test --watchAll=false
    - echo "Test successful"
Run Code Online (Sandbox Code Playgroud)

构建通过了,但在测试阶段它失败了,抱怨

 $ react-scripts test --watchAll=false
 /bin/sh: 1: react-scripts: not found
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

Ami*_*hah 5

问题似乎来自build_react
\n命令yarn install将在文件夹中安装依赖项node_modules(该文件夹不在存储库的提交文件中,因为它在 中提到.gitignore)。
\n如果您需要其他依赖作业中的依赖项(test_react在您的情况下),则应将它们指定为cacheartifacts
\n因此,build_react可能看起来像这样:

\n\n
\xe2\x8b\xae\n\nbuild_react:\n  stage: build\n  script:\n    - echo "Building deploy package"\n    - yarn install\n    - yarn build\n    - echo "Build successful"\n  artifacts:\n    expire_in: 1 hour\n    paths:\n      - build\n      - node_modules/    ### This will make the modules available to other dependent jobs\n\n\xe2\x8b\xae\n
Run Code Online (Sandbox Code Playgroud)\n