continuous-integration - Gitlab CI react 脚本 : not found

标签 continuous-integration gitlab devops gitlab-ci

我正在尝试为示例 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

enter image description here

最佳答案

看来问题出在build_react :
命令 yarn install将在 中安装依赖项node_modules 文件夹(此文件夹不在存储库的已提交文件中,因为它在 .gitignore 中被提及)。
如果您需要其他依赖作业中的依赖项(在您的情况下为 test_react),则应将它们指定为 cacheartifacts .
因此,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/

相关文章:

c# - TeamCity + MSTest - 只运行失败的测试?

gitlab - 创建要在最终合并之前运行的手动 GitLab CI 作业

asp.net - Azure Web App(ASP.NET MVC)每十分钟变冷一次,加载时间为+ 10-20s

ubuntu - 如何在特定端口上运行 Next.js 项目?

maven - 如何使用 tomcat8-maven-plugin 指定在另一个项目中构建的 WAR 以进行集成测试?

git - 学生作业的持续集成

ios - 持续集成,如何为 QA 和 App Store 发布生成单个构建(二进制)?

python - 如何将 curl 命令作为 python 请求发布?

regex - 我在我的 CI/CD 设置中找不到 Gitlab 的测试覆盖解析设置

azure - 如何在 Azure Devops 中以正确的方式进行基于功能的部署?