Unmeshed Logo

Authoring

Passing Variables

Passing context and variables around steps is a core concept in the process execution pipeline. This is done by templating which dynamically replaces placeholders within inputs with values. This enables the seamless passing of variables between different steps of a process, ensuring that each step has access to the necessary data and context to execute correctly.

Overview

Unmeshed facilitates the dynamic injection of data into inputs by recognizing and replacing placeholders with actual values from various sources. This mechanism supports secure handling of sensitive information such as secrets, flexible configuration through variables, and data flow between different steps within a process.

Video Overview

Syntax for Passing Variables

Variables within inputs are denoted using double curly braces ({{ }}). The syntax allows for optional quotes and supports different data sources. Here's the syntax:

plaintext
ParameterDescription
variablePathThe path indicating the source of the variable, such as secrets, variables, step references, or process inputs.

Variable Types

Secrets

Syntax:

plaintext

Description: References a secret value stored securely. Secrets are typically sensitive information like API keys, passwords, or tokens.

Usage Example:

plaintext

Example in JSON:

json

(Environment) Variables

Syntax:

plaintext

Description: References a predefined variable within the Unmeshed Cluster. Variables can store configuration values or parameters that are reused anywhere across process definitions or steps. This is the equivalent of an environment variable

Usage Example:

plaintext

Example in JSON:

json

Step References

Syntax:

text

Description: References the output from a previous step in the process. This allows subsequent steps to utilize data generated by earlier steps.

Here is the full list of values you can refer to in each step reference

FieldDescription
idA unique identifier for the step context.
parentIdThe identifier of the parent step context, if applicable.
parentExecutionIdThe execution ID of the parent step, if applicable.
stepDefinitionSnapshotA snapshot of the step definition, containing metadata and configuration for the step.
inputKey-value pairs representing the input data for this step.
outputKey-value pairs representing the output or results produced by this step.
statusThe current status of the step Step Status.
workerIdThe identifier of the worker assigned or responsible for executing the step, if present.
priorityA numeric value indicating the priority of this step, often used to determine execution order or importance.
optionalA boolean flag indicating whether this step is optional
startA timestamp (in epoch milliseconds) indicating when the step started.
scheduleA timestamp (in epoch milliseconds) indicating when the step is scheduled to start or run.
updatedA timestamp (in epoch milliseconds) indicating the last time the step’s status or data was updated.
typeThe type of the step.
refA reference to the step.
nameThe name of the step.
namespaceThe namespace under which this step definition belongs.

Usage Example:

plaintext

Example in JSON:

json

Process Inputs

Syntax:

text

Description: References the inputs provided when initiating the process. These inputs can influence the behavior and execution of the process.

Here is the full list of values we support in the context

KeyDescription
processIdThe unique identifier for the process, often the same as processContext.getId().
idAn alias to the process id
requestIdA user supplied identifier for the incoming request triggering or associated with the process.
correlationIdA user supplied identifier used to correlate related processes or requests.
statusThe current status of the process Process Status
stateProcess state that is updated throughout the process executions using __statePut.
secretStateProcess secret state that is updated throughout the process executions using __secretStatePut.
createdThe epoch millis date/time the process or context was initially created.
updatedThe epoch millis date/time the process or context was last updated.
inputThe input data or parameters provided for the process.
outputThe output data or result generated by the process.
nameThe name of the process definition.
namespaceThe namespace under which this process definition belongs.
versionThe version number of the process definition.
typeThe type or category of the process definition (e.g., “API_ORCHESTRATION”, “STANDARD”).
authClaimsClaims from the token with which this process was ran.

Usage Example:

plaintext

Example in JSON:

json

Using State and Secret State

You can access shared data across steps using the context.state and context.secretState references. These represent non-sensitive and sensitive values that were added using __statePut and __secretStatePut respectively.

Syntax:

plaintext

These values can also be deeply nested.

Example 1: Accessing a simple value from state

If a previous step included this:

json

You can access it like:

json

Example 2: Accessing a nested object from state

If state contains:

json

You can reference:

json

Example 3: Accessing secret state

If a previous step did:

json

You can reference it like:

json
Note

Values in secretState will not appear in logs or execution history but are still fully available during runtime.

Passing Variables Between Steps

To pass inputs into steps from other steps, use the appropriate syntax based on the source of the data. Here's how you can integrate different types of variables within your process steps:

Define the output in the Source Step: Ensure that the step generating the data exposes the necessary output. Reference the output in the Target Step: Use the steps syntax to access the output from the source step.

Example Workflow

Data Processing

Output from Source:

json

Target Input definition

json

Usage Examples

Example 1: Using Secrets

Scenario: Injecting a database password securely into a configuration.

Template:

json

Resolved Output:

json

Example 2: Using Variables Scenario: Setting the maximum number of retries for a process.

Input Definition:

json

Resolved Output:

json

Example 3: Referencing Step Outputs Scenario: Using the result from a data processing step in a subsequent step.

json

Resolved Output:

json

Example 4: Accessing Process Inputs Scenario: Utilizing user-provided input to customize a process step.

json

Resolved Output:

json

Best Practices

  • Secure Handling of Secrets: Always use the secrets prefix to handle sensitive information. Avoid exposing secrets in logs or error messages.
  • Consistent Naming Conventions: Use clear and consistent names for variables, secrets, and step references to enhance readability and maintainability.
  • Error Handling: Implement appropriate error handling to manage scenarios where a referenced variable or secret might be missing or invalid.
  • Documentation: Document the purpose and usage of each variable and secret to aid team members in understanding the process flow.
  • Avoid Hardcoding Values: Utilize variables and secrets instead of hardcoding values to make the process more flexible and secure.
  • Validate Inputs: Ensure that the inputs provided to the process are validated to prevent issues during template resolution.
  • Monitor and Log: Keep track of variable resolutions and monitor for any discrepancies or failures in the template resolution process.