Environment context not recongnised

I’m having trouble with a conditional not being recognised when deploying in production.

The Jekyll templating:

{% if jekyll.environment == 'production' %}
  <meta name="robots" content="INDEX, FOLLOW">
{% else %}
  <meta name='robots' content="noindex,nofollow" />
{% endif %}

netlify.toml

# Production context:
# All deploys from the main repository branch
[context.production]
  JEKYLL_ENV="production"

# Branch deploys
[context.branch-deploy]
  JEKYLL_ENV="dev"

Netlify recognises the production deployment
deploys
Netlify deploy log

However, the final html isn’t as expected
site source

Any ideas where I’m going wrong with this?

I have the same problem.

In toml:

[context.production.environment]
DATABASE_URL_ENV_VAR = "DATABASE_URL_PROD"

Then I have DATABASE_URL_PROD set in the UI.

Then I’m reading it in the function:

const handler = async (event: Event, context: Context) => {
  console.log(process.env) // doesn't have the DATABASE_URL_ENV_VAR

How about using the built in read only CONTEXT variable?

Another post that’s double posted in helpdesk as well as forums :slight_smile:

The short answer is, variables defined in netlify.toml are not accessible to serverless Functions.

@hrishikesh - my initial question was not to do with serverless functions and I’ve not posted to helpdesk.

Any insight on where I’m using environment context incorrectly?

Hey @wesort,

About the duplicate post, I was talking about @alexbezh, not you.

In your case, the problem is because, the variables should be used under context.production.environment.

1 Like

Thank you @hrishikesh - that’s working for me now.

Thanks for coming back and letting us know! Happy building!