在CircleCI构建目录中找不到package.json

问题描述 投票:1回答:1

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

project structure

-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 run 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

我不知道在我的配置中两次设置工作目录是否正确,但它至少设置为两个差异。工作。

更新

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

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
continuous-integration yaml circleci
1个回答
0
投票

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

你应该为你的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
© www.soinside.com 2019 - 2024. All rights reserved.