【问题标题】:Can't find package.json in directory in CircleCI build在 CircleCI 构建的目录中找不到 package.json
【发布时间】:2019-04-20 13:28:21
【问题描述】:

我有一个包含 两个子项目的存储库。只是为了完整性,前端项目和 firebase 云功能项目(都使用单独的 package.jsons)。现在对于这个项目,我想同时开始两个工作。但我无法使用 CircleCI 完成设置。我没有任何缓存配置。

项目结构

-creepy-stories
  -.circleci
  -cloud-functions
    -functions
     package.json
  -frontend
   package.json

config.yml

version: 2.1
jobs:
  cloud-functions:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories/cloud-functions/functions

    steps:
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run build

  frontend:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories/frontend
    steps:
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run build
      - run: npm run test:coverage

workflows:
  version: 2
  cloud-functions_and_frontend:
    jobs:
      - cloud-functions
      - frontend

所以现在我想我的问题是环境找不到我的 package.json 文件。打印的错误如下所示:

npm 运行 lint

#!/bin/bash -eo pipefail
npm run lint
npm ERR! path /home/circleci/creepy-stories/frontend/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/circleci/creepy-stories/frontend/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/circleci/.npm/_logs/2019-04-20T13_08_45_252Z-debug.log
Exited with code 254

我不知道在我的配置中设置两次工作目录是否正确,但至少设置了两次diff。工作。

更新

如果我签出项目的根目录然后cd 到所需的文件夹并执行脚本,我设法让它工作。但这并不是真正的 DRY(不要重复自己)也许你们中的一些人有更好的解决方案:

version: 2.1

jobs:
  cloud-functions:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories

    steps:
      - checkout
      - run: cd cloud-functions/functions && npm install
      - run: cd cloud-functions/functions && npm run lint
      - run: cd cloud-functions/functions && npm run build

  web:
    docker:
      - image: circleci/node:10.8.0

    working_directory: ~/creepy-stories
    steps:
      - checkout
      - run: cd web && npm install
      - run: cd web && npm run lint
      - run: cd web && npm run build
      - run: cd web && npm run test:coverage

workflows:
  version: 2
  concurrently:
    jobs:
      - cloud-functions
      - web

【问题讨论】:

  • 作业是否同时开始?我想这是第一件事。您是否有两个可用的构建服务器(即付费计划)来允许这样做?
  • 您已为其中一项工作报告了npm run lint,npm install 是否对这两项工作都成功了?如果没有,你会发布两个输出吗?
  • 不,我不需要为 CI 流程构建服务器。是的,npm install 确实成功了。
  • “不,我不需要为 CI 流程构建服务器”。您误解了我的评论 - 我在问您是否有多个 CircleCI 服务器来实现您正在寻求的并行性。

标签: continuous-integration yaml circleci


【解决方案1】:

结帐时,您会自动将 git 存储库的根目录复制到当前工作目录中。如果您希望您的工作目录成为根目录的子目录,则需要为检出步骤提供一个路径,将文件复制到工作目录的父目录中。

例子:

working_directory: ~/creepy-stories/cloud-functions
steps:
  - checkout:
      path: ~/creepy-stories

文档链接:https://circleci.com/docs/2.0/configuration-reference/#checkout

【讨论】:

  • 此设置为我提供了您尝试签出的目录 (/home/circleci/creepy-stories) 不是空的,也不是 git 存储库。那是因为 cloud-functions 文件夹存在于令人毛骨悚然的故事中
【解决方案2】:

我认为您有一个添加目录。

您应该向您的 CircleCi 前端任务添加一个额外的运行,该任务执行 pwd,然后是 ls -la。

您可能会发现结帐最终位于与您的存储库同名的目录中。

编辑以回答后续问题:

如果我没记错的话,checkout 命令总是把它放在服务器的根目录下,所以你可以更新工作目录来适应它。像这样

    working_directory: ~/creepy-stories/web
    steps:
      - checkout
      - run: npm install
      - run: npm run lint
      - run: npm run build
      - run: npm run test:coverage

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-28
    • 2021-03-20
    • 2020-01-22
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    相关资源
    最近更新 更多