Jekyll.environment inconsistency in Jekyll build vs serve

Hi All,

OS: Windows 10
Jekyll: 3.8

I have a project of two files.

_config.yml

environment: production

index.html

---
---
<div><h1>jekyll.environment: {{ jekyll.environment  }}</h1></div>

Execution in Docker container (PowerShell)

build

$JEKYLL_VERSION=3.8
docker run --rm `
  --volume="$(pwd):/srv/jekyll:Z" `
  -it jekyll/builder:$JEKYLL_VERSION `
  jekyll build

serve

$JEKYLL_VERSION=3.8
docker run --rm `
  --volume="$(pwd):/srv/jekyll:Z" `
  --publish 127.0.0.1:4000:4000 `
  jekyll/jekyll:$JEKYLL_VERSION `
  jekyll serve

Output (_sites)

build

<div><h1>jekyll.environment: production</h1></div>

serve

<div><h1>jekyll.environment: development</h1></div>

Is this an expected behavior difference between the two?
Seems serve cannot handle environment being set in configuration files and defaults always to development.
Is this a bug?

Thank you,
Gabor

normally you would set the env via the command line - like jekyll serve JEKYLL_ENV=production - at least I think that is correct. I saw an example with the env stuff before the command.

I think for serve the default is always development and for build it is production.

I did not see anything saying you can set it inside the config file so I think what you are doing isn’t even being shown in the site folder, try changing the config env you have to something random and I bet you get the same thing as you are now.

If you could set it via the config file I think it would be via JEKYLL_ENV but setting it in the config file seems like a bad idea as how would that work? that would seem to defeat the purpose of an env variable.

1 Like

Thank you for the quick response @rdyar !

Here is what I found in the docs:

Jekyll gives you a lot of flexibility to customize how it builds your site. These options can either be specified in a _config.yml or _config.toml file placed in your site’s root directory, or can be specified as flags for the jekyll executable in the terminal. Configuration | Jekyll • Simple, blog-aware, static sites

So all config options, including jekyll.environment, I would expect as a valid entry in the configuration files.
No syntax errors, and with build that works pretty well (does not fall back to a default production)

However, serve is different, and my question is around that.

I would prefer configuration files over environment variables because with them it is easy to manage environments with different configs easily. And if I have multiple files already, then it would also make sense to include the environment config itself into them.

Configuration
Specify config files instead of using _config.yml automatically. Settings in later files override settings in earlier files.
--config FILE1[,FILE2,...]
Configuration Options | Jekyll • Simple, blog-aware, static sites

Regards,
Gabor