• Pricing
Skip to content

Environments

On this page:

Loading...

Environments allow you to use different values in your website depending on where it is deployed. For example, you could use a different CDN for your development, staging and production sites.

To change the environment variables for your site:

  1. Go to the Site Settings / Configuration section
  2. Create/edit your environment key and value under Environment Variables
  3. Click Update Build Details

CloudCannon defaults to production. Running Jekyll locally defaults to development.

shell
$ JEKYLL_ENV=production bundle exec jekyll serve

Jekyll exposes the environment with jekyll.environment. You can use this to create separate configurations.

Here’s a short example using variables from _config.yml:

_config.yml
development:
  asset_url: "http://localhost:1337/"
  app_url: "http://localhost:3000/"

staging:
  asset_url: "https://staging.example.org/assets/"
  app_url: "https://staging.example.org/"

production:
  asset_url: "https://cdn.example.org/"
  app_url: "https://app.example.org/"
index.html
---
---
<!DOCTYPE html>

<html>
  <head>
    <title>Environment Test</title>
  </head>
  <body>
    <p>Environment: {{ jekyll.environment }}</p>
    <p>Asset URL: {{ site[jekyll.environment].asset_url }}</p>
    <p>App URL: {{ site[jekyll.environment].app_url }}</p>
    <p>Development Asset URL: {{ site.development.asset_url }}</p>
    <p>Production Asset URL: {{ site.production.asset_url }}</p>
    <p>Staging Asset URL: {{ site.staging.asset_url }}</p>
    <p>Development App URL: {{ site.development.app_url }}</p>
    <p>Staging App URL: {{ site.staging.app_url }}</p>
    <p>Production App URL: {{ site.production.app_url }}</p>
  </body>
</html>
On this page:

Loading...

Don’t miss the latest
CloudCannon news freshly delivered to your inbox
Illustration of woman holding an envilope