Yaml:yaml文件中的格式错误。预期为'<document start =“”>',但发现为'<block mapping =“” start =“”>

时间:2019-04-02 15:14:32

标签: yaml circleci

  version: 2.1
  executors:
    docker-publisher:
      environment:
        IMAGE_NAME: vinaya.nayak/mocking-service
      docker:
        - image: circleci/buildpack-deps:stretch
  jobs:
    build:
       executor: docker-publisher
       steps:
         - checkout
         - setup_remote_docker
         - run:
            name: Build Docker image
            command: |
              docker build -t $IMAGE_NAME:latest .
         - run:
            name: Archive Docker image
            command: docker save -o mocking.tar $IMAGE_NAME
         - persist_to_workspace:
              root: .
              paths:
                - ./mocking.tar
  publish-latest:
      executor: docker-publisher
      steps:
        - attach_workspace:
            at: /tmp/workspace
        - setup_remote_docker
        - run:
            name: Load archived Docker image
            command: docker load -i /tmp/workspace/mocking.tar
        - run:
            name: Publish Docker Image to Docker Hub
            command: |
                  echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
                  docker push docker.kfz42.de/v2/java/mocking-service/$IMAGE_NAME:latest .
workflows:
  version: 2
  build-master:
    jobs:
      - build:
          filters:
           branches:
             only: master
      - publish-latest:
          requires:
            - build
          filters:
            branches:
              only: master

有人可以帮助我解决yaml文件的问题吗?我收到以下错误。我什至尝试使用yaml格式化程序,并且yaml格式化程序说这是有效的yaml文件

  

!/ bin / sh -eo pipefail无法解析YAML预期的“”,但在“字符串”的第39行中找到了“   第1列:工作流程:警告:此配置已自动生成为   向您显示以上消息。不要重新运行这项工作。运行将有   没有效果。 false以代码1退出

2 个答案:

答案 0 :(得分:1)

  version: 2.1
  executors:
    docker-publisher:
      environment:
        IMAGE_NAME: vinaya.nayak/mocking-service
      docker:
        - image: circleci/buildpack-deps:stretch
  jobs:
    build:
       executor: docker-publisher
       steps:
         - checkout
         - setup_remote_docker
         - run:
            name: Build Docker image
            command: |
              docker build -t $IMAGE_NAME:latest .
         - run:
            name: Archive Docker image
            command: docker save -o mocking.tar $IMAGE_NAME
         - persist_to_workspace:
              root: .
              paths:
                - ./mocking.tar
  publish-latest:
      executor: docker-publisher
      steps:
        - attach_workspace:
            at: /tmp/workspace
        - setup_remote_docker
        - run:
            name: Load archived Docker image
            command: docker load -i /tmp/workspace/mocking.tar
        - run:
            name: Publish Docker Image to Docker Hub
            command: |
                  echo "$DOCKER_HUB_PASSWORD" | docker login -u "$DOCKER_HUB_USERNAME" --password-stdin
                  docker push docker.kfz42.de/v2/java/mocking-service/$IMAGE_NAME:latest .
  workflows:
    version: 2
    build-master:
      jobs:
        - build:
            filters:
             branches:
               only: master
        - publish-latest:
            requires:
              - build
            filters:
              branches:
                only: master

我通过将workflows缩进2个空格来解决了上述问题

答案 1 :(得分:0)

您的文件以缩进两个空格的键/值对开头,因此您有一个作为映射的根节点。只要将所有其他根级别也缩进两个空格,就可以了。

workflows没有缩进,这就是解析器期望一个新文档的原因。