Overview
With our latest update, you can now set Level variables directly from within your script. Previously, setting a variable required capturing a script’s entire output (and ensuring it was clean) to assign that value to a variable—this often forced users to write short glue scripts just to format output properly.
Now, you can freely output anything in your script, and simply use a dedicated syntax to set a Level Variable on the fly. This change improves flexibility, reduces complexity, and lets you keep your existing scripts largely unchanged.
Why This Matters
No More Glue Scripts: Write scripts normally without worrying about output cleanliness or single-line formatting.
More Flexible Workflows: Keep using standard logging or other outputs—only the designated syntax line will be parsed to set the variable.
Improved Readability: Maintain easy-to-read, maintainable scripts that also integrate seamlessly with Level automations.
How It Works
Within your script, include the following syntax wherever you want to set a Level variable:
{{variable_name=value}}
Example: Setting an IP Address Variable in PowerShell
Here’s how you might capture the local IP address of a machine during a deployment script and assign it to a Level automation variable called local_ip
:
# Retrieve the local IP address
$ip = (Get-NetIPAddress -AddressFamily IPv4 |
Where-Object {$_.IPAddress -ne "127.0.0.1" -and $_.InterfaceAlias -notlike "*Loopback*"} |
Select-Object -First 1 -ExpandProperty IPAddress)
# Output some logging info
Write-Output "Detected local IP address: $ip"
# Set the Level automation variable
{{local_ip=$ip}}
In this example:
We use
Get-NetIPAddress
to get the machine’s IPv4 addresses, then filter out loopback addresses and select the first available one.We output the IP address using
Write-Output
(for logs or debugging).We set the Level variable by including the special syntax:
{{ local_ip = $ip }}
.Level’s agent will parse this line during script execution and assign the variable
local_ip
the value of$ip
.
This syntax can appear anywhere in the script output. Level’s agent will parse these lines and assign the variables accordingly.
Key Benefits
Inline Simplicity: No need for separate lines or glue logic—just embed the syntax within your existing scripts.
Language-Agnostic: Works in any script that can produce text output—PowerShell, Bash, ZSH, etc.
Non-Intrusive: Allows other script outputs (logs, status, etc.) to flow through untouched.
Implementation Notes
The agent scans the output of your script for the
{{ variable_name = value }}
pattern and sets the variable accordingly.All other output is ignored for this purpose—so you can freely log, print, or display anything else.
Variables set using this method persist throughout the workflow and can be used in subsequent automation steps.
Conclusion
This enhancement makes working with automation variables easier and more powerful than ever. Say goodbye to glue scripts and output juggling—just run your scripts and set variables inline. For more information, visit our documentation or contact our support team.