Configuring Environments When Building Sites With Jekyll

Setting Up & Configuring Your Configuration Files.

  • Create your secret/environment file. This file should be stored at the root of your project (i.e. the same level as _config.yml). I called mine _environment.yml. This is a standard YAML file which you can add key-value pairs such as:
service-url: "https://url-to-this-environments-service" user-name: "A User"
  • Add the new file(s) to your .gitignore file:
  • Start your site. Depending on your environment the command can start to get quite long. I generally create a script to start sites locally:
#!/usr/bin/env bash set -euo pipefail bundle exec jekyll serve -c _config.yml,_environmet.yml --watch --future --livereload
$ jekyll build -c _config.yml,_environmet.yml

Using Your New Configuration Values.

--- layout: null ---
$.getJSON("{{ site.ENVIRONMENTVARIABLE  }}", function (data) {};



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andy Crouch

Andy Crouch

Experienced CTO, technical architect, board advisor & technical leader. I focus on building distributed applications & great teams.