Fix 'Build script returned non-zero exit code 42' Error When Deploy Jekyll Sites on Netlify

 

The Error

Activating bundler (2.0.2) failed:
Could not find 'bundler' (2.0.2) required by your /opt/build/repo/Gemfile.lock.

Error running command: Build script returned non-zero exit code: 42

Netlify Log:

11:29:15 AM: Activating bundler (2.0.2) failed:
11:29:15 AM: Could not find 'bundler' (2.0.2) required by your /opt/build/repo/Gemfile.lock.
11:29:15 AM: To update to the latest version installed on your system, run `bundle update --bundler`.
11:29:15 AM: To install the missing version, run `gem install bundler:2.0.2`
11:29:15 AM: Checked in 'GEM_PATH=/opt/buildhome/.rvm/gems/ruby-2.6.2:/opt/buildhome/.rvm/rubies/ruby-2.6.2/lib/ruby/gems/2.6.0', execute `gem env` for more information
11:29:15 AM: To install the version of bundler this project requires, run `gem install bundler -v '2.0.2'`
11:29:15 AM: Skipping functions preparation step: no functions directory set
11:29:15 AM: Caching artifacts
11:29:15 AM: Started saving ruby gems
11:29:15 AM: Finished saving ruby gems
11:29:15 AM: Started saving node modules
11:29:15 AM: Finished saving node modules
11:29:15 AM: Started saving pip cache
11:29:15 AM: Finished saving pip cache
11:29:15 AM: Started saving emacs cask dependencies
11:29:15 AM: Finished saving emacs cask dependencies
11:29:15 AM: Started saving maven dependencies
11:29:15 AM: Finished saving maven dependencies
11:29:15 AM: Started saving boot dependencies
11:29:15 AM: Finished saving boot dependencies
11:29:15 AM: Started saving go dependencies
11:29:15 AM: Finished saving go dependencies
11:29:18 AM: Error running command: Build script returned non-zero exit code: 42
11:29:18 AM: Failing build: Failed to build site
11:29:18 AM: failed during stage 'building site': Build script returned non-zero exit code: 42
11:29:18 AM: Finished processing build request in 2m13.428750696s

How to fix

The last 2 lines of Gemfile.lock have specified the version of bundler:

BUNDLED WITH
   2.0.2

Change this version to your installed version of bundler(2.0.1 for me) and you are good to go.

References

Netlify’s Docker Image