"Build failed due to a user error: Build script returned non-zero exit code: 2"

Hello! Any help with my failing deployment would be much appreciated!

My build setting:


I had changed it to ci= npm run build and add environment variable CI= false but it didn’t work so I changed it back to the original build setting as above.

1:38:44 PM: build-image version: 481fab764dc8f5343ed2ea2af1bdecd396c657eb (focal)
1:38:44 PM: buildbot version: 481fab764dc8f5343ed2ea2af1bdecd396c657eb
1:38:45 PM: Fetching cached dependencies
1:38:45 PM: Starting to download cache of 257.1MB
1:38:48 PM: Finished downloading cache in 3.134s
1:38:48 PM: Starting to extract cache
1:38:49 PM: Finished extracting cache in 1.055s
1:38:49 PM: Finished fetching cache in 4.262s
1:38:49 PM: Starting to prepare the repo for build
1:38:49 PM: Preparing Git Reference refs/heads/main
1:38:50 PM: Parsing package.json dependencies
1:38:50 PM: Starting build script
1:38:50 PM: Installing dependencies
1:38:50 PM: Python version set to 2.7
1:38:51 PM: Started restoring cached Node.js version
1:38:51 PM: Finished restoring cached Node.js version
1:38:52 PM: v16.19.1 is already installed.
1:38:52 PM: Now using node v16.19.1 (npm v8.19.3)
1:38:52 PM: Enabling Node.js Corepack
1:38:52 PM: Started restoring cached build plugins
1:38:52 PM: Finished restoring cached build plugins
1:38:52 PM: Attempting Ruby version 2.7.2, read from environment
1:38:53 PM: Using Ruby version 2.7.2
1:38:53 PM: Using PHP version 8.0
1:38:53 PM: Installing Hugo 0.97.3
1:38:53 PM: hugo v0.97.3-078053a43d746a26aa3d48cf1ec7122ae78a9bb4+extended linux/amd64 BuildDate=2022-04-18T17:22:19Z VendorInfo=gohugoio
1:38:53 PM: Started restoring cached go cache
1:38:53 PM: Finished restoring cached go cache
1:38:53 PM: Installing Go version 1.17 (requested 1.17)
1:38:59 PM: go version go1.17 linux/amd64
1:39:00 PM: Detected 0 framework(s)
1:39:00 PM: Section completed: initializing
1:39:01 PM: ​
1:39:01 PM:   Netlify Build                                                 
1:39:01 PM: ────────────────────────────────────────────────────────────────
1:39:01 PM: ​
1:39:01 PM: ❯ Version
1:39:01 PM:   @netlify/build 29.6.8
1:39:01 PM: ​
1:39:01 PM: ❯ Flags
1:39:01 PM:   baseRelDir: true
1:39:01 PM:   buildId: 6410b123cff5940008555b5e
1:39:01 PM:   deployId: 6410b123cff5940008555b60
1:39:01 PM: ​
1:39:01 PM: ❯ Current directory
1:39:01 PM:   /opt/build/repo
1:39:01 PM: ​
1:39:01 PM: ❯ Config file
1:39:01 PM:   /opt/build/repo/netlify.toml
1:39:01 PM: ​
1:39:01 PM: ❯ Context
1:39:01 PM:   production
1:39:01 PM: ​
1:39:01 PM: ❯ Loading plugins
1:39:01 PM:    - netlify-plugin-hugo-cache-resources@0.2.1 from netlify.toml
1:39:02 PM: ​
1:39:02 PM:   1. netlify-plugin-hugo-cache-resources (onPreBuild event)     
1:39:02 PM: ────────────────────────────────────────────────────────────────
1:39:02 PM: ​
1:39:02 PM: Checking if resources exist at "resources"
1:39:02 PM: Restored cached resources folder. Total files: 2
1:39:02 PM: ---
1:39:02 PM: 1. /opt/build/repo/resources
1:39:02 PM: 2. /opt/build/repo/resources/_gen
1:39:02 PM: ​
1:39:02 PM: (netlify-plugin-hugo-cache-resources onPreBuild completed in 52ms)
1:39:02 PM: ​
1:39:02 PM:   2. build.command from netlify.toml                            
1:39:02 PM: ────────────────────────────────────────────────────────────────
1:39:02 PM: ​
1:39:03 PM: $ hugo --gc --minify -b $URL
1:39:03 PM: Start building sites …
1:39:03 PM: hugo v0.97.3-078053a43d746a26aa3d48cf1ec7122ae78a9bb4+extended linux/amd64 BuildDate=2022-04-18T17:22:19Z VendorInfo=gohugoio
1:39:03 PM: Error: Error building site: "/opt/build/repo/content/home/accomplishments.md:26:1": failed to unmarshal YAML: yaml: line 25: did not find expected key
1:39:03 PM: Total in 130 ms
1:39:03 PM: ​
1:39:03 PM:   "build.command" failed                                        
1:39:03 PM: ────────────────────────────────────────────────────────────────
1:39:03 PM: ​
1:39:03 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:39:03 PM:   Error message
1:39:03 PM:   Command failed with exit code 255: hugo --gc --minify -b $URL (https://ntl.fyi/exit-code-255)
1:39:03 PM: ​
1:39:03 PM:   Error location
1:39:03 PM:   In build.command from netlify.toml:
1:39:03 PM:   hugo --gc --minify -b $URL
1:39:03 PM: ​
1:39:03 PM:   Resolved config
1:39:03 PM:   build:
1:39:03 PM:     command: hugo --gc --minify -b $URL
1:39:03 PM:     commandOrigin: config
1:39:03 PM:     environment:
1:39:03 PM:       - HUGO_VERSION
1:39:03 PM:       - HUGO_ENABLEGITINFO
1:39:03 PM:       - HUGO_ENV
1:39:03 PM:     publish: /opt/build/repo/public
1:39:03 PM:     publishOrigin: config
1:39:03 PM:   plugins:
1:39:03 PM:     - inputs:
1:39:03 PM:         debug: true
1:39:03 PM:       origin: config
1:39:03 PM:       package: netlify-plugin-hugo-cache-resources
1:39:03 PM: Caching artifacts
1:39:03 PM: Started saving build plugins
1:39:03 PM: Finished saving build plugins
1:39:03 PM: Started saving pip cache
1:39:03 PM: Finished saving pip cache
1:39:03 PM: Started saving emacs cask dependencies
1:39:03 PM: Finished saving emacs cask dependencies
1:39:03 PM: Started saving maven dependencies
1:39:03 PM: Finished saving maven dependencies
1:39:03 PM: Started saving boot dependencies
1:39:03 PM: Finished saving boot dependencies
1:39:03 PM: Started saving rust rustup cache
1:39:03 PM: Finished saving rust rustup cache
1:39:03 PM: Started saving go dependencies
1:39:03 PM: Finished saving go dependencies
1:39:03 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:39:03 PM: Failing build: Failed to build site
1:39:04 PM: Finished processing build request in 19.078s

@chenyunj The cause of the build failure is the error on this line:

1:39:03 PM: Error: Error building site: "/opt/build/repo/content/home/accomplishments.md:26:1": failed to unmarshal YAML: yaml: line 25: did not find expected key

You should check the contents of the accomplishments.md file.

1 Like

Solved! I just found that one of the date format I put was wrong. Thank you for your help!