Learn more about using shared Variables in Knock.

Variables within Knock let you set shared constants or secrets that you can use in all of the workflows and templates under your account. Variables can be overridden at the environment level to set per environment constants.

Setting variables

You can create account-wide variables under "Settings > Variables". Each variable has a key and a value. The key is how you'll reference the variable in your templates, conditions, and preference conditions when building your workflows.

Setting secret variables

By default, any variables you set are created as public. Public variables are exposed via the user feed endpoint and are always visible within the dashboard by all team members. If you're working with variables that should not be exposed you can create them as secret variables by toggling the "Set as secret" slider when creating a variable.

Secret variables are never revealed in the dashboard (all values are obfuscated) and are never exposed via the API.

Accessing variables

Variables are available to be accessed under the vars namespace within your templates, step conditions, and preference conditions. For instance, if you set a variable with the key base_url you can access that variable under vars.base_url.

Overriding variables per-environment

You can optionally override any account variables per environment to set environment-specific variables. You can set an environment variable under the "Developers > Variables" section in each environment.

Setting JSON in variables

Your variables can optionally contain JSON, which will be parsed when a variable is executed. For instance, if you want to set a dynamic batch window for each environment you can set a per-environment variable to contain { "unit": "seconds", "value": 30 }.

Please note: variables will always be parsed as JSON first, before falling back to being processed as a string.