Skip to main content

env() Function

The env() function retrieves an environment variable of the jsPolicy pod as a string. If the environment variable cannot be found undefined is returned.

Example#

This example only prints to the log stream if the environment variable DEBUG is set.

apiVersion: policy.jspolicy.com/v1beta1
kind: JsPolicy
metadata:
name: "env.example.com"
spec:
operations: ["CREATE"]
resources: ["pods"]
javascript: |
// env() retrieves an environment variable from the jspolicy container
if (env("DEBUG") === "true") {
print("Log this Pod Creation to the console"))
}