Nested and referenced variables in Jaws Deploy enhance the flexibility of your deployment configurations by allowing variables to incorporate or depend on the values of other variables. This feature enables dynamic, context-aware setups where values are resolved at runtime based on the deployment environment, tags, machines, or cloud targets. It's particularly useful for creating modular and reusable configurations, reducing redundancy in complex workflows.
In enterprise migrations from tools like Bamboo, nested variables help replicate dynamic substitutions, while referenced variables ensure seamless integration in scripts and steps. This article explains nesting (how variables can include others in their values), referencing (how to access them in steps and scripts), syntax, examples, rules, and limitations, based on Jaws Deploy's variable system.
Nesting Variables
Nesting allows you to define a variable's value using the value of another variable. When editing workspace or project variables, you can embed references to other variables within a value. These nested values are resolved based on the deployment context, just like standard variable resolution.
Syntax
Use the following syntax to nest variables:
#{VAR.variable_name}
Example
Suppose you have a base variable BasePath set to C:\\\\Apps\\\\. You can nest it in another variable InstallPath as #{VAR.BasePath}MyApp. During deployment, InstallPath resolves to C:\\\\Apps\\\\MyApp, depending on the context (e.g., scoped overrides for BasePath).
This nesting can chain multiple levels, but be cautious of potential complexity in resolution.
Rules and Limitations
- Nested values resolve using the same scoping rules as the parent variable—more specific scopes (e.g., machine) override broader ones (e.g., environment).
- If the nested variable doesn't resolve (e.g., no matching scope), the parent may fail or use a default, depending on the context.
- No explicit limit on nesting depth is mentioned, but deep chains may increase resolution time or risk circular references (not supported; avoid to prevent errors).
- Nesting works in variable values but not in scopes themselves.
Referencing Variables
Referenced variables are accessed within deployment steps or scripts to inject their resolved values. Jaws Deploy provides specific syntax for different contexts, ensuring variables are evaluated correctly at runtime.
In Deployment Steps
Every deployment step is based on a step template with a GUI JSON definition. When editing a project step in the UI, text inputs support variable references.
Syntax
#{VAR.variable_name}
Example
In a "Run Script" step's body or a "Deploy Package" step's path field, use #{VAR.InstallationDirectory} to insert the resolved value (e.g., C:\\\\Apps\\\\MyApp).
In Deployment Scripts
PowerShell deployment scripts have access to the full context, including resolved variables.
Syntax
$Jaws.Parameters["VAR.variable_name"].Value
Example
In a script:
$installPath = $Jaws.Parameters["VAR.InstallationDirectory"].Value
Write-Host "Installing to $installPath"
This outputs the resolved path during execution.
Rules and Limitations
- References resolve based on the current deployment context (environment, tags, machine/cloud target).
- If a reference doesn't match any scope, it may resolve to an empty string or cause an error—always define defaults for unscoped cases.
- Expressions can include logic like conditionals (e.g., #{if VAR.isProd then "prod-value" else "dev-value"}), but nesting within expressions follows the same rules.
- Scripts must handle null/empty values gracefully to avoid failures.
Best Practices
- Use nesting for composable configs (e.g., base + env-specific suffixes) to keep variables DRY.
- Test references with debug mode (
__debug = true) to log resolutions and spot issues. - For enterprises, nest secrets carefully to maintain security—avoid exposing in non-Prod scopes.
- During migrations, map Bamboo variables to nested structures for dynamic behavior.
Conclusion
Nested and referenced variables add power to your Jaws Deploy configurations, enabling dynamic resolutions that adapt to contexts. Master them for efficient, error-free deployments.
For more, see Variables guide or Project Steps Explained. Experiment in a project—add a nested variable today! New to Jaws? Start with Getting Started.
