Did you know that CF2018 imports environment vars into the Server scope?
Note: This blog post is from 2020. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.This is a hidden gem that I never saw documented anywhere: CF2018 now imports environment variables into the CF "server" scope, specifically:
and java system properties into:
(Thanks to Sean C for catching a mistake in the initial post.)
I learned of it last year when Pete F tweeted about it, and I assumed someone else would do a post about it, but the topic came up in a discussion today and I was surprised to not be able to find any mention of it, other than that and his mention of it in his cfdocs.org site.
And yes, Lucee had it first (as proposed initially in 2015). :-)
The feature can be useful, whether you're setting such vars when running a (Docker) container, or via JVM args, etc., and you want to be able to access them within CFML.
For more content like this from Charlie Arehart:Need more help with problems?
- Signup to get his blog posts by email:
- Follow his blog RSS feed
- View the rest of his blog posts
- View his blog posts on the Adobe CF portal
- If you may prefer direct help, rather than digging around here/elsewhere or via comments, he can help via his online consulting services
- See that page for more on how he can help a) over the web, safely and securely, b) usually very quickly, c) teaching you along the way, and d) with satisfaction guaranteed
server.system.environment is the environment variables.
(the cfdocs.org site gets this right by the way)
An important difference is that programs cannot change environment variables but they can modify/add system properties (using java.lang.System/setProperty).
It's also important to observe that although you can assign to server.system.properties and server.system.environment, those do not affect the actual environment or properties available via Java.
A final, equally important observation is that if a program changes properties while it is running (via setProperty() above), the server data structure does not reflect those change!
p.s. I don't see the updates on the blog post yet!