Jekyll environment at build time not working

I am using GitLab CI to build and deploy the Jekyll website but it is not working with the environments.

Your statement hardly makes sense.
What environments?? What is the error?

This is the gitlab-ci.yml file and here I have used the variable called JEKYLL_ENV: production and it is not working.

# This file is a template, and might need editing before it works on your project.
# Template project: https://gitlab.com/pages/jekyll
# Docs: https://docs.gitlab.com/ce/pages/
image: ruby:2.3

variables:
  JEKYLL_ENV: production

before_script:
- bundle install

test:
  stage: test
  script:
  - bundle exec jekyll build -d test
  artifacts:
    paths:
    - test

pages:
  stage: deploy
  script:
  - bundle exec jekyll build -d public JEKYLL_ENV=$JEKYLL_ENV
  artifacts:
    paths:
    - public
  only:
  - master

Environment variables are generally passed before the command invocation:

JEKYLL_ENV=$JEKYLL_ENV bundle exec jekyll build -d public

Tried that, still not working.