CircleCI config.yml 用于 nodejs

CircleCI config.yml for nodejs

version: 2
  jobs:
    test:
      docker:
        - image: circleci/node:12.16
      steps:
        - checkout
        - run: echo "Running tests"
        - run: npm install
        - run: npm test
      build:
        docker:
          - image: circleci/node:12.16
        steps:
          - checkout
          - run: echo "build project"
          - npm install
          - npm run build
workflows:
  version: 2
    test_build:
      jobs:
        - test
        - build:
          requires:
            - test

上面的 YAML 是我的 config.yml CircleCI,但是我得到这个错误

Config does not conform to schema: {:workflows {:test_and_build {:jobs [nil {:build (not (map? nil)), :requires (not (map? a-clojure.lang.LazySeq))}]}}}

另一个观察结果是,如果我 运行 并行作业,它们 运行 没有任何错误。 也就是说,如果我删除要求: - 测试如下所示

workflows:
  version: 2
    test_build:
      jobs:
        - test
        - build

build 是一份工作,就像 test 一样,应该像这样缩进:

version: 2
  jobs:
    test:
      docker:
        - image: circleci/node:12.16
      steps:
        - checkout
        - run: echo "Running tests"
        - run: npm install
        - run: npm test
    build:
      docker:
        - image: circleci/node:12.16
      steps:
        - checkout
        - run: echo "build project"
        - npm install
        - npm run build

workflows:
  version: 2
    test_build:
      jobs:
        - test
        - build:
          requires:
            - test

我试过这个,很管用。前一个问题似乎与版本控制有关。 CircleCI cloud 2.1 和CircleCI server 2。另外,这次我决定使用节点球

version: 2.1

orbs:
  node: circleci/node@3.0.1

jobs:
  build:
    working_directory: ~/backend_api
    executor: node/default
    steps:
      - checkout
      - node/install-npm
      - node/install-packages:
          app-dir: ~/backend_api
          cache-path: node_modules
          override-ci-command: npm i
      - persist_to_workspace:
          root: .
          paths:
            - .

  test:
    docker:
      - image: cimg/node:current
    steps:
      - attach_workspace:
          at: .
      - run:
          name: Test
          command: npm test

workflows:
  version: 2
  build_and_test:
    jobs:
      - build
      - test:
          requires:
            - build