Variables
Accessing variables in Mage
You’ve got all of these great variables and secrets, now let’s put them to use. Learn how to access them in your code. 🦸🏻♂️
Mage allows users to interpolate variables specific to your pipeline or project. The following syntax is specific to yaml
and SQL
files.
Here’s a list of the different variables and functions you can use in your code:
Syntax | Description |
---|---|
{{ env_var('secret') }} | Get secret from environment variables. |
{{ variables('secret') }} | Get secret from runtime variables. |
{{ mage_secret_var('secret') }} | Get secret from Mage secrets. |
{{ aws_secret_var('secret') }} | Get secret from AWS Secrets Manager. |
{{ azure_secret_var('secret') }} | Get secret from Azure Key Vault. |
{{ json_value(json_obj, 'key') }} | Extract value from a JSON string. |
{{ n_days_ago(N) }} | Get the date N days ago (data integration pipelines only). |
Mage Pro only variable syntax
Only in Mage Pro.
Try our fully managed solution to access this advanced feature.
Syntax | Description |
---|---|
{{ file('path/to/file.txt') }} | Load the contents of a local file. |
File content syntax
This is useful for dynamically loading configuration files, secrets, or text assets during pipeline execution. The path can be either abosulte path or relative path to the project.
Example Usage
If you want to get a json field from the local file, you can use it together with the json_value
syntax like