YAML: 没有找到期望的键。

8
  • 解析配置文件出错: yaml: 第22行: 没有找到期望的键
  • 在配置文件的 jobs: 部分中找不到名为 build 的作业。

我得到了这些错误,但是我对yaml非常陌生,所以我无法找到它不起作用的原因。有什么想法吗?有人说可能有额外的空格或其他内容,但我真的找不到它。

yaml 文件

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

参见:https://dev59.com/M2Af5IYBdhLWcg3w_Gyr - dreftymac
3个回答

3
你想做的是将两个序列合并,即将默认序列的所有元素合并到步骤序列中。这在YAML规范中是不支持的。只能合并映射和嵌套序列。
以下内容是无效的:
steps:
  <<: *defaults
  - run:

as <<: 用于合并map元素,而不是序列。

如果您这样做:

 step_values: &step_values
   - run ...
steps:
  - *defaults
  - *step_values
你最终会得到嵌套的序列,这不是你想要的。

1

0

看起来你的YAML格式不正确。你可以通过开源网站(例如http://www.yamllint.com/)检查YAML的结构验证。

在检查yaml文件时,第22行有错误。正如Srikanth所解释的那样,你正在尝试合并两个序列。即将default的所有元素合并到steps中。这在目前的YAML中是不支持的。

只能合并映射和嵌套序列 如果你这样做:

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

你最终将得到嵌套的序列,这不是你的本意。

1
为什么要抄袭别人的答案呢? - Offlein

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接