Skip to main content

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:

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

Variable Types

Secrets

Syntax:

{{ secrets.secretName }}

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

Usage Example:

{{ secrets.databasePassword }}

Example in JSON:

{
"database": {
"password": "{{ secrets.databasePassword }}"
}
}

(Environment) Variables

Syntax:

{{ variables.variableName }}

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:

{{ variables.retryCount }}

Example in JSON:

{
"maxRetries": "{{ variables.retryCount }}"
}

Step References

Syntax:

{{ steps.stepRef.output.key }}

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:

{{ steps.dataProcessing.output.result }}

Example in JSON:

{
"processedData": "{{ steps.dataProcessing.output.result }}"
}

Process Inputs

Syntax:

{{ context.input.inputKey }}

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
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:

{{ context.input.userId }}

Example in JSON:

{
"userId": "{{ context.input.userId }}"
}

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:

{
"result": "Processed Data"
}

Target Input definition

{
"result": "{{ steps.dataProcessing.output.result }}"
}

Usage Examples

Example 1: Using Secrets

Scenario: Injecting a database password securely into a configuration.

Template:

{
"database": {
"password": "{{ secrets.databasePassword }}"
}
}

Resolved Output:

{
"database": {
"password": "s3cr3tP@ssw0rd"
}
}

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

Input Definition:

{
"maxRetries": "{{ variables.retryCount }}"
}

Resolved Output:

{
"maxRetries": 5
}

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

{
"processedData": "{{ steps.dataProcessing.output.result }}"
}

Resolved Output:

{
"processedData": "Processed Data"
}

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

{
"userId": "{{ context.input.userId }}"
}

Resolved Output:

{
"userId": "user_12345"
}

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.