Search code examples
reactjsamazon-web-servicespipelinecicd

How to fix YAML_FILE_ERROR. Download_source State: failed


Running on CodeBuild On-demand
Waiting for agent ping
Waiting for DOWNLOAD_SOURCE
Phase is DOWNLOAD_SOURCE
CODEBUILD_SRC_DIR=/codebuild/output/src2136787222/src
YAML location is /codebuild/output/src2136787222/src/buildspec.yml
DOWNLOAD_SOURCE State: FAILED
Phase context status code: YAML_FILE_ERROR Message: did not find expected key at line 15

buildspec.yml

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 16
    commands:
      - echo Entering dashboardclient directory
      - cd dashboardclient
      - echo Installing frontend dependencies
      - npm install
  build:
    commands:
      - echo Building frontend
      - npm run build
   post_build:
    commands:
      - echo Frontend build complete
      - echo Listing contents of dashboardclient directory
      - ls -la  # Check current directory
      - ls -la dashboardclient  # Check contents of dashboardclient directory
      - echo Listing contents of build directory
      - ls -la dashboardclient/dist  # Check contents of build directory

artifacts:
  files:
    - '**/*'
  base-directory: 'dashboardclient/dist'

Solution

  • YAML is not properly indented at line 16 (post_build).

    Fixed YAML:

    version: 0.2
    
    phases:
      install:
        runtime-versions:
          nodejs: 16
        commands:
          - echo Entering dashboardclient directory
          - cd dashboardclient
          - echo Installing frontend dependencies
          - npm install
      build:
        commands:
          - echo Building frontend
          - npm run build
        post_build:
          commands:
            - echo Frontend build complete
            - echo Listing contents of dashboardclient directory
            - ls -la  # Check current directory
            - ls -la dashboardclient  # Check contents of dashboardclient directory
            - echo Listing contents of build directory
            - ls -la dashboardclient/dist  # Check contents of build directory
    
    artifacts:
      files:
        - '**/*'
      base-directory: 'dashboardclient/dist'