Scheduling variables

Updated at:

Multiple nodes in a workflow often need the same values, such as environment identifiers, table name prefixes, and business thresholds. Declaring scheduling parameters on each node individually is costly to maintain, and parameter values cannot be changed after a run starts. Scheduling variables allow you to define variables centrally in the schedule settings of a workflow. Nodes within the workflow can directly reference these variables in their code, achieving a define-once, effective-everywhere approach. Variable values can also be overwritten by a Set Variable node during execution, enabling dynamic cross-node value passing.

Note

Scheduling variables are a workflow-level feature and are currently supported only in the new Data Studio.

Key concepts

Scheduling variables and scheduling parameters are two different types of configurations. The differences are as follows.

Comparison item

Scheduling variable

Scheduling parameter

Definition location

Schedule settings of the workflow.

Schedule settings of the node or workflow.

Value mutability

An initial value is defined before execution and can be modified by a Set Variable node during execution. Nodes that run after the Set Variable node can obtain the updated value.

Determined before execution starts and remains unchanged during execution.

Runtime override method

Can be reassigned by a Set Variable node.

Not supported.

Effective scope

All nodes within the workflow.

  • Node parameter: The current node only.

  • Workflow parameter: All nodes within the workflow.

Value range

When defining a parameter, you can use

time expressions such as $bizdate and $[yyyymmdd-1].

Reference syntax

${workflow.variable.variable_name}

  • Node parameter: ${parameter_name}

  • Workflow parameter: ${workflow.parameter_name}

Typical use cases

Values shared across multiple nodes, such as environment identifiers, table prefixes, and thresholds; dynamic value passing during execution.

Dynamically computing partitions and other business dates based on the scheduling time.

Use cases

  • Centralized management of shared values: Values shared across multiple nodes, such as environment identifiers, MaxCompute project names, table name prefixes, and alert thresholds, are defined once at the workflow level. Each node directly references them. When a modification is needed, you only need to update the variable value instead of maintaining each node individually.

  • Dynamic cross-node value passing: Used together with Set Variable nodes, an upstream node can overwrite a scheduling variable during execution, and downstream nodes within the workflow directly read the latest value. Unlike context parameters of a Set Variable node, which can only be passed to direct downstream nodes one level down, scheduling variables can be passed to indirect downstream nodes without configuring input parameters layer by layer between nodes.

  • Temporary values for debugging: When you debug a workflow, you can specify values for variables for the current run to verify the execution results under different values without affecting the saved initial values.

Three ways to override variable values

The value of a scheduling variable consists of the initial value (the value saved in the workflow schedule settings) and the runtime value (the value that actually takes effect during a specific run). The three override methods differ as follows.

Override method

Entry point

Scope

Whether the initial value is modified

Temporary assignment at runtime

When you debug or run a workflow, specify the value in Run Configurations.

Current run only.

No

Override during execution

Add a Set Variable node to the workflow to write a new value.

Within the current run, nodes that run after this node read the latest value.

No

Modify initial value

Edit the variable value in the workflow schedule settings, save, and deploy.

All subsequent runs (new instances on the production side).

Yes

  • Temporary assignment at runtime overrides only the value of the variable with the same name. Variables not specified in the run configurations still use their initial values. Specifying a variable name that is not defined in the workflow does not take effect.

  • Override during execution takes effect in node execution order: nodes that run after the Set Variable node read the latest overridden value. This method applies only to the current run and does not affect the initial value saved in the workflow.

  • Modify initial value requires redeploying the workflow to take effect in production. After deployment, newly generated scheduled instances use the new value, while existing instances are not affected.

Prerequisites

  • You have opened the new Data Studio.

  • Workflow variables are supported only when you use a serverless resource group.

  • You have created a scheduled workflow or a manual workflow and have edit permissions on the workflow.

Instructions

Step 1: Define scheduling variables

  1. Go to the Data Studio page, double-click the target workflow, and open the workflow editing canvas.

  2. Click Schedule Settings on the right side and find the Scheduling Variable section.

  3. Click Add Variable and enter the variable information.

    Configuration item

    Description

    Variable name

    The unique identifier of the variable, which must be unique within the workflow. We recommend that you use only letters, digits, and underscores.

    Variable value

    The initial value of the variable.

    • Each time a task starts, the variable takes effect starting from this value. You can specify a constant, workspace parameter, or time expression such as $[yyyy-mm-dd]. For more information, see Scheduling parameter sources and expressions.

    • Referencing workflow parameters (such as ${workflow.parameter_name}) or the output values of Set Variable nodes in the value is not supported.

    Examples: env=prod, ds_flag=$[yyyymmdd].

  4. Save the workflow.

Note

After you delete a variable, the node code that references it is not automatically modified. Before you delete a variable, make sure that no nodes reference it. Otherwise, the placeholder is retained as-is at runtime and is not replaced.

Step 2: Reference the variable in node code

In the code of a node within a workflow, use the ${workflow.variable.variable_name} format to reference scheduling variables. Variable names support letters, digits, underscores, and hyphens.

Take a SHELL node as an example. Configure env and ds_flag on the workflow, enter the following code in the code editor, and save.

#!/bin/bash
echo "env=${workflow.variable.env}"
echo "ds_flag=${workflow.variable.ds_flag}"

At runtime, the system replaces placeholders with the current values of the variables for this run (either initial values or values overwritten during this run) before the node executes, and then passes the code to the engine for execution.

  • Scheduling variables and scheduling parameters can be used together: ${workflow.variable.env} is replaced according to scheduling variable rules, while ${bizdate} is still replaced with the business date according to scheduling parameter rules.

  • An unknown variable name does not cause a replacement error. The placeholder is kept as-is in the code. Make sure that the referenced variables are defined on the workflow.

  • Scheduling variables can only be referenced in the code area. Writing ${workflow.variable.variable_name} in a parameter value in the schedule settings script parameters does not retrieve the variable value.

  • Extracting a partial value from a variable is not supported. Notations such as ${workflow.variable.variable_name[0][1]} and ${workflow.variable.variable_name.name} are invalid. To split a value, use a Set Variable node to compute the result with Shell or Python3 and write it to another variable.

Step 3: Test run

  1. On the workflow editing canvas, click Run at the top of the page.

  2. In the Run Parameters form, modify the value for this run in the workflow variables column as needed. The value assigned here is a temporary value for the debug run, takes effect only for this run, and does not change the initial value of the variable.

  3. Execute the run and check the variable replacement results in the node runtime log to verify that they match expectations.

Note

Variable values modified in the run configuration take effect only for the current run and are not written back to the initial variable values saved in the workflow.

Step 4: Use a Set Variable node to modify variables at runtime

To modify variable values during a run, add a Set Variable node to the workflow. This node is a general-purpose node that supports Shell and Python3. It writes new values by printing assignment markers to standard output in the script. The following rules apply.

  1. Each time a workflow runs, the system creates a copy of the scheduling variables for that run. When a node in the workflow executes, the ${workflow.variable.variable_name} placeholders in the code are replaced with values from this copy.

  2. Before a Set Variable node executes, the ${workflow.variable.variable_name} placeholders in its script are also replaced with the current values of the variables. This allows the script to read existing variable values before computing new ones.

  3. During script execution, new values are written by printing assignment markers to standard output. Two formats are supported:

    • Single-line format: ##WORKFLOW_VARIABLE::variable_name=value.

    • Multi-line format: Starts with ##WORKFLOW_VARIABLE_BEGIN::variable_name and ends with ##WORKFLOW_VARIABLE_END::variable_name. This format is suitable for values that contain line breaks, such as multi-line data.

    # Read variable env, compute and overwrite variable ds_flag
    echo "current env: ${workflow.variable.env}"
    echo "##WORKFLOW_VARIABLE::ds_flag=20260903"
    # Multi-line assignment
    echo "##WORKFLOW_VARIABLE_BEGIN::result_json"
    echo '{"name":"shirt","count":50}'
    echo '{"name":"coat","count":120}'
    echo "##WORKFLOW_VARIABLE_END::result_json"
  4. After the node executes successfully, the system parses the assignment markers in the standard output and writes the new values back to the variable copy for the current run. Nodes that run after this node will obtain the new values when referencing ${workflow.variable.variable_name}.

Note
  • You can only assign values to variables that are already defined on the workflow. Assigning values to undefined variables has no effect. If none of the assignment markers match any defined variable, the node fails.

  • Overwrites take effect only for the current run and do not affect the initial values saved in the workflow schedule settings or other running instances. If the node fails, assignment markers are not parsed and the variables retain their pre-overwrite values.

  • The default upper limit for the total variable data in a single run is 2 MB.

  • Set Variable nodes can only run on serverless resource groups and require Standard Edition or later. For the complete configuration items, usage limits, and multi-branch examples, see "Set Variable node".

Step 5: Deploy and verify

  1. After testing is complete, submit and deploy the workflow to the production environment. Scheduling variables are deployed together with the workflow.

  2. After successful deployment, go to Operation Center and verify that the variable replacement results in the scheduled tasks match expectations.

Note

If the variable values of a production task do not match expectations, check whether the workflow was deployed successfully.

Example: Use scheduling variables in a multi-branch workflow

The following example builds a pipeline with branching and merging: a Shell Set Variable node produces statistical results, and three downstream branches consume the results in parallel (one branch further overwrites a date, one performs threshold-based validation, and one writes alert messages). The merge node reads the final values of all variables. Constants are defined centrally, and runtime results are passed along the dependency order without redundant declarations across nodes.

image

Step 1: Define variables

Add 7 variables in the workflow schedule settings.

Variable name

Variable value (initial value)

Purpose

env

daily

Environment identifier, used to compose table names.

tbl_prefix

dwd_

Table name prefix, used to compose table names.

ds_flag

(empty)

Date identifier, relayed and overwritten by Set Variable nodes.

stats_json

{}

Statistics result, written in multi-line format by a Shell Set Variable node.

chain_flag

(empty)

Relay flag, written by a Python3 Set Variable node.

quality_threshold

100

Quality check threshold.

alert_msg

(empty)

Alert message, written in multi-line format by an alert-branch Set Variable node.

Step 2: Build the node pipeline

Create the following six nodes and configure their dependencies as described in the table below: set_ds_flag branches into three paths, and summary_report merges the three paths.

Node

Type or language

Upstream

Purpose

set_ds_flag

Set Variable node / Shell

None

Reads initial values; writes ds_flag and stats_json.

assign_next_day

Set Variable node / Python3

set_ds_flag

Reads the updated ds_flag, modifies it, and writes chain_flag.

assign_alert_msg

Set Variable node / Python3

set_ds_flag

Assembles an alert message from variables and writes it to alert_msg in multi-line format.

quality_check

Python node

set_ds_flag

Parse stats_json and validate against quality_threshold.

prepare_report

Python node

assign_next_day

Read the relayed ds_flag, chain_flag, and stats_json.

summary_report

Python node

quality_check, assign_alert_msg, prepare_report

Read the final values of all variables and output a summary.

The code of the three Set Variable nodes is as follows.

  1. Set Variable node set_ds_flag. Set the language type of the Set Variable node to SHELL.

    # set_ds_flag (variable assignment node, Shell)
    #!/bin/bash
    echo "env=${workflow.variable.env} tbl=${workflow.variable.tbl_prefix} ds_flag(before)=${workflow.variable.ds_flag}"
    echo "##WORKFLOW_VARIABLE::ds_flag=20260903"
    echo "##WORKFLOW_VARIABLE_BEGIN::stats_json"
    echo "{\"table\":\"${workflow.variable.tbl_prefix}user_trade_${workflow.variable.env}\",\"rows\":120,\"ok\":true}"
    echo "##WORKFLOW_VARIABLE_END::stats_json"
  2. Set Variable node assign_next_day. Set the language type of the node to python3.

    # assign_next_day (variable assignment node, Python3)
    print("[b_py] ds_flag(a)=" + "${workflow.variable.ds_flag}")
    stats = """${workflow.variable.stats_json}"""
    print("[b_py] stats_json=" + stats)
    print("##WORKFLOW_VARIABLE::ds_flag=20260904")
    print("##WORKFLOW_VARIABLE::chain_flag=py-touched")
  3. Set Variable node assign_alert_msg. Set the language type of the node to python3.

    # assign_alert_msg (variable assignment node, Python3)
    msg_table = "${workflow.variable.tbl_prefix}" + "user_trade_" + "${workflow.variable.env}"
    print("[alert_assign] build alert for " + msg_table)
    print("##WORKFLOW_VARIABLE_BEGIN::alert_msg")
    print("[DAILY-ALERT] table: " + msg_table)
    print("[DAILY-ALERT] ds: ${workflow.variable.ds_flag}")
    print("please contact: dw-group-01")
    print("##WORKFLOW_VARIABLE_END::alert_msg")

The code of the three consumer nodes is as follows.

  1. Python node quality_check.

    # quality_check (Python node)
    rows = __import__("json").loads("""${workflow.variable.stats_json}""").get("rows", 0)
    ts = int("${workflow.variable.quality_threshold}")
    print("[quality] rows=%s threshold=%s -> %s" % (rows, ts, "PASS" if rows >= ts else "WARN"))
  2. Python node prepare_report.

    # prepare_report (Python node)
    print("[prepare] ds_flag=" + "${workflow.variable.ds_flag}" + " chain=" + "${workflow.variable.chain_flag}")
    stats = """${workflow.variable.stats_json}"""
    print("[prepare] report table rows from stats_json=" + stats)
  3. Python node summary_report.

    # summary_report (Python node)
    print("[summary] ds_flag(final)=" + "${workflow.variable.ds_flag}")
    print("[summary] chain=" + "${workflow.variable.chain_flag}")
    stats = """${workflow.variable.stats_json}"""
    print("[summary] stats_json=" + stats)
    msg = """${workflow.variable.alert_msg}"""
    print("[summary] alert_msg=" + msg)
Note

When the value contains quotation marks, such as JSON content, the replacement result is directly substituted into the code. Wrap the value according to the syntax rules of the host language (in Python, use """..."""). Otherwise, a script syntax error occurs.

Step 3: Run the workflow and verify results

Go back to the workflow canvas and click the run button on the toolbar. After the workflow runs, the key output in the logs of each node is as follows. Variable values are passed sequentially in the order in which the nodes run.

Node

Key log output

Description

set_ds_flag

ds_flag(before)=unset

The initial value is displayed at the start of the run. Then ds_flag=20260903 and stats_json are written.

assign_next_day

ds_flag(a)=20260903

The new value from the previous step is read. Then the value is changed to 20260904 and chain_flag is written.

assign_alert_msg

build alert for dwd_user_trade_daily

tbl_prefix and env are combined into a table name. Then a multi-line alert_msg is written.

quality_check

rows=120 threshold=100 -> PASS

stats_json is parsed and the threshold validation is completed.

prepare_report

ds_flag=20260904 chain=py-touched

The final date and relay flag after relaying are read.

summary_report

ds_flag(final)=20260904 and alert_msg=[DAILY-ALERT] table: dwd_user_trade_daily

After the three branches converge, all final variable values are available.

Note

The overrides described above take effect only for the current run and do not affect the initial values saved in the workflow. After the run completes, if you open the Scheduling Variable panel again, the initial value of ds_flag is still unset, and alert_msg is still empty.

Pass variables between parent and child workflows

When a workflow references another workflow through a subprocess node, the referenced workflow is the child workflow. Parent and child workflows each define their own scheduling variables with non-overlapping scopes. To pass a value from the parent workflow to the child workflow, you can reset the child workflow's variable on the parent workflow's subprocess node: set the Reset Value of the child workflow variable to a reference to the parent workflow variable. At runtime, the child workflow starts with the value passed from the parent workflow.

The parameters of a subprocess node are divided into two sections: Workflow Parameters and Workflow Variables. The Workflow Variables section displays the variable names defined in the child workflow, the variable values (initial values saved in the child workflow), and the reset values. Only the reset values are editable.

Three passing scenarios

Scenario

Configuration

Runtime behavior

The parent workflow assigns an initial value to a child workflow variable, and the child workflow overwrites it internally afterward.

Reset the variable on the subprocess node and set the reset value to a reference to the parent workflow variable. Also keep the Set Variable node in the child workflow.

The child workflow starts with the value passed from the parent workflow. After the Set Variable node runs, downstream nodes use the new value.

The value from the parent workflow takes effect throughout the entire child workflow run.

Reset the variable on the subprocess node and do not configure a Set Variable node for that variable in the child workflow.

All nodes in the child workflow read the value passed from the parent workflow.

The child workflow is not affected by the parent workflow.

Do not reset the variable on the subprocess node (leave the reset value empty).

The child workflow uses its own initial value saved in the schedule settings.

Configuration steps

  1. In the editing canvas of the parent workflow, add a SUBPROCESS node.

  2. In the Workflow Variables section, find the child workflow variable to which you want to pass a value. You can also click the edit icon in the upper-right corner of the node on the canvas to modify it later.

  3. In the Reset Value field, enter a reference to the parent workflow variable, such as ${workflow.variable.env}. Leave it empty to skip resetting, in which case the child workflow uses its own initial value.

  4. Save and deploy the parent workflow. If the variable definitions of the child workflow change, you must also redeploy the child workflow.

Note
  • You can only reset variables that are already defined in the child workflow. Variables not defined in the child workflow do not appear in this section and cannot be created through the subprocess node.

  • The scope of a variable is still bounded by the workflow. When a node in the child workflow references ${workflow.variable.variable_name}, it reads the child workflow's own variable (whose value may have been reset by the parent workflow). It cannot directly reference the parent workflow's variables.

  • Variable passing is one-way from the parent workflow to the child workflow and takes effect only for the current run. It does not modify the initial values saved in the child workflow.

Notes

  • Scope restriction: Scheduling variables take effect only for nodes within the workflow where they are defined. Variables in different workflows are invisible to each other. To reuse variables across workflows, you must define them separately in each workflow.

  • Naming restriction: Variable names cannot be duplicated within the same workflow. Scheduling variables and scheduling parameters are two independent substitution channels with different reference syntax (${workflow.variable.variable_name} vs. ${parameter_name}).

  • Choosing between parameters and variables: Use scheduling parameters when values must be dynamically calculated based on the scheduling time (such as business dates). Use scheduling variables when values are constants or need to be overwritten at runtime.

  • When initial values take effect: At the start of each run, variables begin with their initial values. Values overwritten during a run take effect only for that run and do not affect the initial values.

  • Runtime override methods: Variable values can be changed at runtime only through Set Variable nodes. References to variables in regular node code are read-only, meaning the node code itself cannot modify variable values. An assignment node cannot overwrite scheduling variables. Instead, it passes values to the directly downstream nodes through node context parameters (outputs).

FAQ

  • Q: Can scheduling variables be used in manual workflows?

    A: Yes. Both scheduled workflows and manual workflows support scheduling variables. The definition and reference methods are the same.

  • Q: If I change a variable value during a debug run, does it affect production scheduling?

    A: No. Variable values specified in the run configuration take effect only for the current run. Production scheduling uses the initial variable values saved in the workflow and the results overwritten by Set Variable nodes.

  • Q: What happens if I reference an undefined variable?

    A: Referencing an undefined scheduling variable does not cause an error. The placeholder ${workflow.variable.variable_name} is kept as-is in the code during execution (for example, in a Shell scenario, this may further cause a script syntax error). Make sure that the referenced variable is defined in the workflow.

  • Q: Can I use time expressions as scheduling variable values?

    A: Yes. Variable values support constants, workspace parameters, and time expressions such as $[yyyy-mm-dd]. However, you cannot reference workflow parameters (such as ${workflow.parameter_name}) or output values from Set Variable nodes in variable values.

  • Q: How soon do scheduling variables take effect after deployment?

    A: Scheduling variables take effect when the workflow is deployed. Instances that have already been generated are not affected. Instances generated in the next scheduling cycle use the values from the latest deployment.

References