`jekyll build` has error but gitlab ci still continues - jekyll

I have a Jekyll website running on Gitlab Pages, and one of my pages contained an error.
This error is found and reported by Jekyll, but the website is still deployed, just without that page.
In Gitlab's job output I see the following:
$ jekyll build -d public
...
Bundle complete! 5 Gemfile dependencies, 29 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux-musl]
Configuration file: /builds/TheOddler/mjb/_config.yml
Source: /builds/TheOddler/mjb
Destination: /builds/TheOddler/mjb/public
Incremental build: disabled. Enable with --incremental
Generating...
Error: YAML Exception reading /builds/TheOddler/mjb/_work/immaculate.md: (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1
Jekyll Feed: Generating feed for posts
done in 1.104 seconds.
Auto-regeneration: disabled. Use --watch to enable.
Uploading artifacts for successful job 00:09
Uploading artifacts...
So it shows Error: YAML Exception ... but then still continues as if everything is OK.
The job in my .gitlab-ci.yml file looks like this:
build-jekyll:
stage: build
image: jekyll/jekyll:4.2.0
script:
- jekyll build -d public
artifacts:
paths:
- public
only:
- master
Why does this happen? And is there a way to make the process fail, or at least report this as a warning so I know something went wrong?
Thanks!

This happens because Jekyll, dispite the error in the output, returns with exit code 0. You could try to add the --strict_front_matter option to let Jekyll return a non-zero exit code.

Related

jekyll serve throws 'no implicit conversion of Hash into Integer ' error

I am following Michael Hartl's Learn Enough CSS course. My current folder layout is as follow:
- _layouts
- _site
index.html
where index.html is:
---
layout: test
---
and I have test.html in _layouts as:
Hello again, world.
Whenever I run jekyll serve, I get this error:
Error reading file /Users/pj/Documents/LETGD/repos/pohjie.github.io/_layouts/test.html: no implicit conversion of Hash into Integer
Error reading file /Users/pj/Documents/LETGD/repos/pohjie.github.io/index.html: no implicit conversion of Hash into Integer
Does anyone have any idea what's happening? I'm using M1 MacBook, not sure if that is a possible cause as I spent a lot of time install Ruby as well.
Thanks!
While downgrading certainly works, it may be pretty annoying and (depending on where you need this) problematic. If you just want a simple workaround, you can make use of the fact that jekyll build still works with Ruby 3 and just serve the page separately:
bundler exec jekyll build && bash -c 'cd _site && python -m http.server 3000'
The only downside of this is that you lose the automatic reload. If you change anything, you need to restart jekyll. But you can run this in a Ruby 3 environment without fiddling with the environment itself.
Quoting from this source:-
Github-Pages uses Jekyll 3.9, which isn’t compatible with Ruby 3.
Downgrading to Ruby 2.7 should avoid the problem.
This worked for me.
Downgrading to Ruby 2.7 is an option (as others have said) which I didn't feel like doing, so I did this instead:
Apply the patch to pathutil
From Liviu Stefan's answer:
Ruby 3.0 deprecated using the last argument as keyword parameters. A double splat ** has to be added before the variable for the behavior to be supported.
Here's how I applied the patch locally:
sudo sed -i.bak 's/, kwd/, **kwd/' $(gem which pathutil)
After that I got another error:
/var/lib/gems/3.0.0/gems/jekyll-3.9.0/lib/jekyll/commands/serve/servlet.rb:3:in `require': cannot load such file -- webrick (LoadError)
Which I fixed by running (from bundle exec jekyll serve: cannot load such file):
bundle add webrick
Ruby 3.0 deprecated using the last argument as keyword parameters. A double splat ** has to be added before the variable for the behavior to be supported.
It's fairly straightforward to amend locally; the relevant patch is found: here
Which needs to be applid to:
/home/<your_user_name>/gems/gems/pathutil-0.16.2/lib/pathutil.rb

How to solve Jekyll-Include-Cache issue?

I am currently trying to open an already created website made through Jekyll. I use the cd command through the terminal to get to the website file that I pulled from Github. Once I get to the file, I run bundle exec Jekyll serve and it shows this error message:
Dependency Error: Yikes! It looks like you don't have Jekyll-include-cache or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. The full error message from Ruby is: 'cannot load such file -- Jekyll-include-cache' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!
Jekyll 3.8.5 | Error: Jekyll-include-cache
So I then do gem install Jekyll-include-cache and the issue remains. Does anyone know how to fix this??
The error message means that Jekyll couldn't load the plugin properly.
Ensure that you have listed the plugin in your Gemfile:
# Gemfile
gem "jekyll-include-cache"

Jekyll SystemStackErorr "stack level too deep" on serve with github pages

I can't serve a jekyll site locally and I get notified that there is a problem with GitHub pages when I commit to GitHub.
bundle exec jekyll -v 11:28:34
jekyll 3.7.3
ruby --version 11:28:42
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
When I run:
bundle exec jekyll serve
will fail and spit out hundreds (more like thousnads) of error messages starting with:
bundler: failed to load command: jekyll (/usr/local/bin/jekyll)
SystemStackError: stack level too deep
/usr/local/lib/ruby/gems/2.5.0/gems/kramdown-1.17.0/lib/kramdown/parser/base.rb:106:in `new'
/usr/local/lib/ruby/gems/2.5.0/gems/kramdown-1.17.0/lib/kramdown/parser/base.rb:106:in `add_text'
/usr/local/lib/ruby/gems/2.5.0/gems/kramdown-1.17.0/lib/kramdown/parser/html.rb:171:in `parse_raw_html'
/usr/local/lib/ruby/gems/2.5.0/gems/kramdown-1.17.0/lib/kramdown/parser/kramdown/html.rb:60:in `handle_kramdown_html_tag'
From what I could tell, this can sometimes happen if you use jekyll serve as opposed to bundle exec jekyll serve and if there is a mismatch between your version of jekyll and the one required by github pages, but here I do use bundle exec and so the correct version of jekyll is used.
jekyll itself works if i try to create a new site with jekyll new blah and i can serve that one locally without a problem, but the combo of jekyll and github pages is giving me grief.
I am puzzled and do not know how to proceed.
All this is on Mac OS X 10.13.6.
Not relating to the original cause of the problem here, but i stumbled upon this and had the error stack level too deep. So i guess this might help someone.
I traced my problem to a field that i named as max in some yaml dictionary in the front matter. Maybe you have named a field which has a special meaning in jekyll.

In Jekyll, how to exclude files based on the JEKYLL_ENV?

This seems like a very basic question but I can't find the answer :-S
I exclude like this:
exclude:
- "*.json"
- "Gemfile*"
- "*.txt"
- vendor
- README.md
- somefile.html
Pretty straightforward. To create the production build I run: $ JEKYLL_ENV=production bundle exec jekyll build
How can I exclude the somefile.html file only when I run the production ENV?
Perhaps you could try using a specific config file for production and one for development. In the production you could exclude the files using exclude as described here.
Then run:
jekyll build --trace --config _config.yml,_config_dev.yml
or
jekyll build --trace --config _config.yml,_config_prod.yml
In the _config.yml you'd set generic settings, and in the config with the environment suffix you'd set a environment specific configuration.
The trace flag is optional, it will help setting it up since it will show occuring errors.
optional: -t, --trace Show the full backtrace when an error occurs

Getting an error with Jekyll serve

Have basically nothing but a _config.yml and index.md file, and when running jekyll serve I'm getting this:
D, [2015-07-08T10:33:29.810161 #14194] DEBUG -- : Celluloid 0.17.0 is running in BACKPORTED mode. [ http://git.io/vJf3J ]
jekyll 2.5.3 | Error: wrong number of arguments (2 for 1)
Please help!
I'm not 100% sure this is the answer for you since I wasn't using Jekyll but I had the same error when I was trying to use compass watch.
Rolling back both Celluloid and Listen did the trick for me.
I added the following to my gemfile:
gem 'listen', '<2.10.0'
gem 'compass', '<0.17.0'