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
Phillip YS
  • 784
  • 3
  • 10
  • 33

3 Answers3

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.

srikanth Nutigattu
  • 1,077
  • 9
  • 15
1

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

pablorsk
  • 3,861
  • 1
  • 32
  • 37
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.

Mohit Sharma
  • 601
  • 6
  • 11