构建工作流
Define custom variables
Custom variables are read-only variables that you can use to store and reuse values in n8n workflows.
Create variables
You can access the Variables tab from either the overview page or a specific project.
To create a new variable:
- On the Variables tab, select Add Variable.
- Enter a Key and Value. The maximum key length is 50 characters, and the maximum value length is 1000 characters. n8n limits the characters you can use in the key and value to lowercase and uppercase letters, numbers, and underscores (
A-Z,a-z,0-9,_). - Select the Scope (only available when creating from the overview page):
- Global: The variable is available across all projects in the n8n instance.
- Project: The variable is available only within a specific project (you can select which project).
- When creating from a project page, the scope is automatically set to that project.
- Select Save. The variable is now available for use in workflows according to its scope.
Edit and delete variables
To edit or delete a variable:
- On the Variables tab, hover over the variable you want to change.
- Select Edit or Delete.
Use variables in workflows
You can access variables in the Code node and in expressions1:
// Access a variable
$vars.<variable-name>All variables are strings.
During workflow execution, n8n replaces the variables with the variable value. If the variable has no value, n8n treats its value as undefined. Workflows don't automatically fail in this case.
Variables are read-only. You must use the UI to change the values. If you need to set and access custom data within your workflow, use Workflow static data.
Footnotes
- Back
In n8n, expressions allow you to populate node parameters dynamically by executing JavaScript code. Instead of providing a static value, you can use the n8n expression syntax to define the value using data from previous nodes, other workflows, or your n8n environment.
官方原文和授权
本页来自 N8N 英文官方网站固定快照,并转换成 xueai 静态页面。内容以 N8N 持续更新的官方页面为准。