yaml: did not find expected key

Phillip YS picture Phillip YS · Aug 2, 2018 · Viewed 18.7k times · Source
  • Error parsing config file: yaml: line 22: did not find expected key
  • Cannot find a job named build to run in the jobs: section of your configuration file.

I got those errors, but I'm really new to yaml so I can't really find reaons why It's not working. any ideas? Some says It might have extra spaces or something, but I can't really find it.

yaml file

defaults: &defaults:
  - checkout
  - restore_cache:
    keys:
      - v1-dependencies-{{ checksum "package.json" }}
      - v1-dependencies-
  - run: npm install
  - save_cache:
      paths:
        - node_modules
      key: v1-dependencies-{{ checksum "package.json" }}

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:10.3.0

    working_directory: ~/repo

    steps:
      <<: *defaults   // << here
      - run: npm run test
      - run: npm run build
  deploy:
    docker:
      - image: circleci/node:10.3.0

      working_directory: ~/repo

    steps:
      <<: *defaults
      - run:
          name: Deploy app scripts to AWS S3
          command: npm run update-app

workflows:
  version: 2
  build-deploy:
    jobs:
      - build
      - deploy:
          requires:
            - build
          filters:
            branches:
              only: master

Answer

srikanth Nutigattu picture srikanth Nutigattu · Aug 2, 2018

What you are trying to do is trying to merge two sequences. ie all elements of default are merged into steps. Which is not supported in YAML spec. Only you can merge maps and nested sequences.

This is invalid:

steps:
  <<: *defaults
  - run:

as <<: is for merging map elements, not sequences

If you do this:

 step_values: &step_values
   - run ...
steps:
  - *defaults
  - *step_values

You will end up with nested sequences, which is not what you intend.