我正在尝试为示例 react 项目构建一个简单的管道。
这是我的 .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"
构建通过了,但在测试阶段它失败了提示
$ react-scripts test --watchAll=false
/bin/sh: 1: react-scripts: not found
最佳答案
看来问题出在build_react
:
命令 yarn install
将在 中安装依赖项node_modules
文件夹(此文件夹不在存储库的已提交文件中,因为它在 .gitignore
中被提及)。
如果您需要其他依赖作业中的依赖项(在您的情况下为 test_react
),则应将它们指定为 cache
或 artifacts
.
因此,build_react
可能看起来像这样:
⋮
build_react:
stage: build
script:
- echo "Building deploy package"
- yarn install
- yarn build
- echo "Build successful"
artifacts:
expire_in: 1 hour
paths:
- build
- node_modules/ ### This will make the modules available to other dependent jobs
⋮
关于continuous-integration - Gitlab CI react 脚本 : not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61000671/