yaml: did not find expected key
Asked Answered
C

3

8
  • 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
Campagna answered 2/8, 2018 at 10:49 Comment(1)
See also: stackoverflow.com/questions/24090177Carte
C
3

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.

Carse answered 2/8, 2018 at 14:18 Comment(0)
S
1

Its not possible for now. Unfortunately, the only solution is to repeat the whole list. Many users are requesting the same feature.

Steakhouse answered 26/3, 2021 at 11:23 Comment(0)
M
0

it looks like your YAML is not written properly. You can always check the structure validation of YAML from an open-source website such as http://www.yamllint.com/.

On checking the yaml file, on line 22 you are doing wrong. As explained by Srikanth, that you are trying to do is merging two sequences. i.e. all elements of default are merged into steps. Which is not supported in YAML at the moment.

Only you can merge maps and nested 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.

Misplay answered 16/4, 2021 at 6:52 Comment(3)
Why copy someone else's answer?Bugs
down-vote in case you copy and paste the answer from others.Clypeus
Your pointer to yamllint.com was super helpful in helping me fix a stray indent at line 28 even though the YAML parser gave the following unhelpful error: yaml: line 22: did not find expected key :(. Thanks!Fadden

© 2022 - 2024 — McMap. All rights reserved.