Skip to content

Set Variable

The set variable step stores key-value pairs in the $vars namespace, which persists across the entire workflow execution. The step editor shows a key-value form where you define variable names and their values.

Set variable step editor with key-value pairs

Each set-variable step merges its output into the existing $vars — it doesn’t replace them. This means values accumulate and you can update individual keys without losing others.

First set-variable step — initialize some state:

KeyValue
offset0
hasMoretrue
items{{ $util.emptyArray }}

Later set-variable step — update specific keys (the others are preserved):

KeyValue
offset100
items{{ $vars.items | arrayConcat: fetch-page.body.data }}

After this, $vars contains { offset: 100, hasMore: true, items: [...] }.

Variables in a single set-variable step are resolved top-to-bottom, so any key can reference a key defined above it in the same step via {{ $vars.key }}. This lets you derive several related values from a single base without spreading them across multiple steps.

Compose related URLs from a single base:

KeyValue
apiBasehttps://api.example.com/{{ $env.STAGE }}
searchUrl{{ $vars.apiBase }}/search
usersUrl{{ $vars.apiBase }}/users
ordersUrl{{ $vars.apiBase }}/orders

After this single step, $vars.apiBase, $vars.searchUrl, $vars.usersUrl, and $vars.ordersUrl are all set — and changing the stage in one place updates them all.

Snapshot a timestamp once and derive a filename from it:

KeyValue
runStartedAt{{ $util.now }}
today{{ $vars.runStartedAt | date: "%Y-%m-%d" }}
reportFilenamereport_{{ $vars.today }}.csv

Capturing runStartedAt once and reusing it guarantees every derived value is based on the same instant — no risk of $util.now returning a slightly different timestamp on each reference.

Accumulate into an array:

KeyValue
tags{{ $util.emptyArray }}
allTags{{ $vars.tags | push: initial.category | push: "automated" }}

Because resolution is sequential within the step, $vars.tags is [] by the time allTags is computed, so allTags becomes [<category>, "automated"].

Accumulating inside a for-each loop:

KeyValue
processedCount{{ $vars.processedCount | plus: 1 }}

Storing computed values for later steps:

KeyValue
fullName{{ initial.firstName }} {{ initial.lastName }}
isVip{{ initial.totalOrders | gte: 100 }}

Access variables anywhere in the workflow:

{{ $vars.processedCount }}
{{ $vars.fullName }}