Home / Articles

Variable Resolution Rules

Variable resolution in Jaws Deploy determines how multi-valued variables are evaluated and selected during a deployment, based on the current context. Variables are designed as multi-valued entities, meaning a single variable can hold different values depending on the deployment context, such as the machine or cloud target being deployed to. This context includes assigned environments and tags, allowing for flexible parametrization of deployment flows.

Understanding these rules is crucial for avoiding unexpected behavior and ensuring precise control over configurations. The rules prioritize specificity and complexity to resolve potential matches, making them reliable for enterprise-scale setups where variables might overlap across environments, tags, machines, or cloud targets.

Scoping Attributes

Variables can be scoped using the following attributes to define when a particular value applies:

  • Environment (typical use-case for differentiating stages like Staging vs. Production).
  • Tags (for grouping machines or targets).
  • Specific machine.
  • Specific cloud target.

Scopes allow you to tailor values to the deployment context. For example, you can create a variable named InstallationDirectory with:

  • C:\\\\deployments\\\\myApp when deploying to the Staging environment.
  • /opt/myApp when deploying to the Production environment.

Resolution Process

When a deployment context matches more than one value for a variable, Jaws Deploy resolves the conflict by selecting the value with the most complex or "strongest" scope. The complexity is determined by the combined amount and importance of the scoping attributes. The importance order is:

  • Specific Cloud Target or Machine (most important).
  • Tag.
  • Environment (least important).

If multiple attributes are specified on a value (e.g., one environment and two tags), they are combined using AND logic between different attributes and OR logic between values of the same attribute. For instance, a scope with { Environment: ['Staging', 'UAT'], Tag: ['tag_A', 'tag_B'] } translates to:(context.Environment == 'Staging' OR context.Environment == 'UAT')

AND

(context.Tags.Contains('tag_A') OR context.Tags.Contains('tag_B')).

The overall scoping strength priorities are:

  • Environment + Machine/CloudTarget (strongest).
  • Machine/CloudTarget.
  • Environment + Tag.
  • Tag.
  • Environment (least important).

This ensures that more specific scopes (e.g., tied to a particular machine) override broader ones (e.g., environment-only).

Examples

Consider the variable InstallationDirectory in a project with:

  • 2 environments (Staging and Production).
  • 1 machine in Staging (StagingServer).
  • 3 machines in Production (ProdServer01, 02, and 03).

Suppose ProdServer03 requires a custom value. The scoped values would be:

  • { value: 'C:\deployments\myAppStaging', scope: { Environment: ['Staging'] } }.
  • { value: 'C:\deployments\myAppProd', scope: { Environment: ['Production'] } }.
  • { value: 'C:\deployments\myAppProd_Custom', scope: { Machine: ['ProdServer03'] } }.

Resolution:

  • Deploying to any Staging server uses the first value due to Environment match.
  • Deploying to any Production server (except ProdServer03) uses the second value due to Environment match.
  • Deploying to ProdServer03 uses the third value, as Machine scoping strength is higher than Environment, overriding the match.

This example highlights how Jaws Deploy prioritizes specificity to select the appropriate value.

Best Practices and Notes on Conflicts

  • Always define scopes from most specific to general to leverage the resolution rules effectively.
  • Test resolutions in a development environment using debug mode (__debug = true) to log how variables are evaluated.
  • Avoid over-scoping to prevent unnecessary complexity, but use it where needed to handle exceptions (like the custom machine in the example).
  • If conflicts arise (e.g., equal strength scopes), review and refine scopes to ensure one is more specific—Jaws Deploy will select based on the defined priorities, but clear hierarchies prevent ambiguity.

These rules make variable management predictable and powerful, supporting complex deployment scenarios while minimizing risks. For more on using variables, see the full Variables guide.