Using n8n custom variables across environments

n8n custom variables hold non-secret, environment-specific values so the same workflow can run in development, staging and production. Secrets belong in credentials, and the page explains which values travel with source control and which do not.

On this page

Using n8n custom variables across environments without hardcoding values

A workflow built in development has to run in production with a different webhook base URL, a different Google Sheet ID, a different Slack channel and perhaps a feature flag turned on only in staging. If those values are typed directly into nodes, every promotion becomes a manual edit that someone can forget or get wrong. n8n custom variables solve this by holding a named value outside the workflow and letting the workflow read it at runtime through an expression such as {{ $vars.VARIABLE_NAME }}. The workflow JSON then carries the variable name, while each instance supplies its own value. n8n offers two scopes for these variables: global variables, shared across the instance, and project variables, limited to one project. Choosing the scope is the first decision, because a value used by every team belongs in global scope, while a value owned by one team's project belongs with that project.

Variables are the right tool for non-secret configuration: URLs, identifiers, environment names, timeouts and toggles. They are the wrong tool for passwords, API keys and OAuth tokens, which belong in credentials so that n8n stores them encrypted and limits who can see them. Before creating a variable, check whether the value is a secret. If it is, create a credential and reference it from the node. Teams also need a naming convention early, since variable names are referenced in expressions across many workflows and renaming one later means editing each reference. Confirm the current naming rules, the maximum number of variables and whether your plan includes project variables in the n8n pricing page and the n8n documentation for your version, because these limits and plan entitlements have changed between releases. Source control determines how variable values move between instances, and that behavior is covered in the sibling sections on environments and Git.

Global and project variables: which scope fits which value

n8n custom variables sit at two scopes, and the scope you pick decides who can change a value and which team sees it. Matching each value to the right scope keeps environment settings predictable as workflows move between instances. The cards below cover scope rules, typical values, what stays out, and what to confirm in your own edition.

Global variables reach every workflow

Global variables are available across the instance, so any workflow on that instance can read them. They suit values that every team on the instance needs, such as a shared base URL for an internal API. Because a global value is visible to all workflows, a change affects every workflow that references it. Before you rely on globals, list which workflows read each one and confirm who in your organization is allowed to edit them.

Queue mode docs

Project variables set team boundaries

Project variables belong to one project, so only workflows in that project can use them. This is the right scope when a value belongs to one team, such as a mailbox name used only by the support project. Project scope lets a team manage its own settings without touching another team's workflows. Check that project roles in your plan let the owners of each project create and edit variables, since that permission is what makes project scope useful.

Who manages each scope

Global variables usually need instance-level administration, while project variables can often be delegated to project editors. Decide this before you create variables, because moving a value between scopes later means updating every reference. Write down the owner for each variable, the reason it exists, and the environment it applies to. Confirm in your edition which roles can create, edit and delete each scope, since permissions differ by plan.

Typical values that belong in variables

Good candidates are non-secret settings that differ between environments: base URLs for development, staging and production APIs, feature flags that switch a branch of logic on or off, and mailbox names for notifications. These values change between instances without changing the workflow logic. Keep the list short and named clearly, so a reviewer can tell from the name alone what the value controls and where it applies.

Values that should not be variables

Passwords, API keys, tokens and OAuth secrets do not belong in variables, even at project scope. Store them as credentials, which n8n encrypts with the instance encryption key and lets you share with users or projects without exposing the secret. Personal data and customer records also stay out of variables. A variable is readable by anyone who can use the workflow, so treat it as configuration, not a vault.

Confirm scopes for your edition

Scope availability depends on your edition and plan, so confirm what your instance exposes before you design around it. Ask whether project-level variables are available to you, which roles can manage each scope, and whether environment-specific values can be set without editing the workflow. Compare the answers with the pricing page, since some environment and source control features are limited to higher plans.

n8n pricing

Variables, credentials and environment settings compared

This table compares the places n8n workflows read configuration from: custom variables, credentials, instance environment variables, the encryption key and an external vault. Read each row by asking what the value is, who can see it and whether it can be committed to Git. The main takeaway is that only non-secret values belong in variables, and secrets stay in credentials or a vault.

MechanismWhat it holds and who can see itTravels with GitWhen it fits
Global variablesNon-secret values such as base URLs or feature switches, stored on the instance. Visibility follows instance roles, so confirm which roles can view or edit them.Confirm with n8n's source control docs whether values sync or only references do before relying on them.Non-secret settings that differ between development, staging and production.
Project variablesNon-secret values scoped to one project. Visible to project members according to their project role. Confirm availability on your plan.Same as global variables. Confirm whether values are exported with the project.Team-owned settings that should not be visible across all projects.
CredentialsEncrypted API keys and OAuth connections stored in the database. Visible only to the owner, admins and users they are shared with.Do not commit credential values. Confirm how source control exports handle credential references.Anything that authenticates to an outside service.
Instance environment variablesSettings read at startup, such as database and queue options, set in the container or host configuration. Visible to anyone who can read that deployment configuration.Deployment files may live in Git, but they must hold no secrets. Keep them in a secrets store or the deployment tool.n8n's own configuration that differs by environment.
Encryption keyThe key that encrypts stored credentials. In queue mode it must be shared with every worker and webhook processor. Visible to administrators with host access.Never commit it. Confirm your backup and rotation procedure before the first deployment.Instance-wide protection of credentials, not a workflow setting.
External vaultShared secrets held in a dedicated vault with its own access policies, audit logs and rotation. Visibility is set by the vault, not by n8n. Confirm which vault integrations your edition supports.Workflows and Git hold only references to vault paths, never the values.When your security team needs central rotation, audit and access policy for secrets.

Naming rules and limits teams hit in practice

Variable names are the contract between an n8n instance and every workflow that reads from it. If a development instance defines API_BASE_URL and production defines apiBaseUrl, a workflow exported from one will reference a name that does not exist on the other, and the failure may only appear when a run reaches that node. Agree on one naming convention before the first variable is created, and write it down with the rest of the environment standards. Choose a single case style (for example, upper snake case for every variable), a prefix or namespace for ownership (such as the team or system the value belongs to), and a rule for how environment is expressed, which is usually by instance rather than by name. The convention matters most during promotion, because a shared naming contract lets a pipeline or reviewer compare two instances and see which variables are missing before a workflow goes live.

The n8n documentation sets rules on what a variable name may contain and how long it may be, and those rules change between releases. Check the current variables section of the n8n docs for the allowed characters, any reserved words, the maximum length, and whether names are case sensitive, and record those limits in your convention so reviewers do not have to rediscover them. Test the limits on a non-production instance with the exact n8n version you run, because a name that works in one release can be rejected or truncated in another. Confirm the same behavior on every instance in the chain, since a name accepted by development but refused by production breaks promotion silently. Also check how variables appear in expressions, because characters that are legal in a name may still need quoting or escaping inside a workflow expression.

Review names before anything leaves the instance where they were created. Run a short check on every workflow that will be exported as JSON, pushed to Git, or packaged, and compare the variable names it references against the target instance's list. Look for near-duplicates such as DB_HOST and DB_HOSTNAME, names with spaces or special characters, and names that encode an environment (for example PROD_ or _STAGING), because these will need to change in every workflow when the same logic moves. Treat a renamed variable as a change that needs a review like any other, since it can break a workflow that was previously working. Keep the naming check in the same review step as your credential check so that sensitive values are not stored under names that suggest they are safe to share.

How variables and credentials move between instances

The diagram starts in a Git-backed development instance, where workflows are edited and committed. Workflows carry only variable names, so the same JSON can move to staging and production unchanged. Each instance then supplies its own variable values and holds its own credentials, which never leave the instance through source control. Check that the boundary between the Git repository and the instance-local values stays where the diagram draws it.

Workflows move through Git, while variable values and credentials stay on each instance.

Setting up custom variables for three environments

This sequence keeps environment-specific values out of n8n workflow definitions, so one workflow can run unchanged across development, staging and production. It produces matching variable names in each instance, expressions that reference them, and a staging test execution that confirms the right values resolve before release.

  1. Inventory variables for each workflow

    Before creating anything in n8n, list every value each workflow reads that changes between development, staging and production, such as base URLs, hostnames, sheet or project identifiers, and feature switches. Record the workflow name, the proposed variable name and the environment that owns each value. The workflow owner and the platform team should both review the table. The step is done when every workflow has a reviewed inventory and no value is left unassigned.

  2. Move secrets into credentials

    Go through the inventory and remove anything that is a secret, including API keys, tokens and passwords. Store those values as credentials in each instance instead, since n8n keeps credential data encrypted in its database under the instance encryption key. Give each credential the same name in every environment so workflows can reference it the same way. Confirm the list of variables now contains only non-sensitive settings. The step is done when no secret appears on the variable list.

  3. Create variables with matching names

    In the development, staging and production instances, create the variables from the inventory using identical names, with the value appropriate to that environment. Confirm with n8n which scope fits your setup, global or project, and check the naming rules and plan requirements in your version before you commit to a naming pattern. Compare the names by listing them in each instance and checking them against the inventory. The step is done when all three instances expose the same names and only the values differ.

  4. Reference variables in expressions

    Update each node that uses an environment-specific value so it reads the variable through an expression, for example with the $vars accessor, instead of a typed literal. Save the workflow in development and run a test execution to confirm each expression resolves to the development value. Look for any node that still contains a hardcoded hostname or identifier. The step is done when a test run completes and a search of the node parameters finds no environment values typed directly into the workflow.

  5. Confirm no secrets appear in JSON

    Export the workflow JSON from the development instance and search it for API keys, tokens, passwords, private hostnames and environment-specific URLs. The file should contain credential references and variable references only. Repeat the check on any package or Git export your team uses, because those files carry the workflow definition in the same form. The step is done when the search returns no secret values and the export matches the reviewed inventory.

  6. Promote the workflow to staging

    Move the workflow to the staging instance using the promotion method your team has chosen, such as source control or a package. Confirm what the method transfers: the workflow should arrive with its variable references, while staging keeps its own variable values and credentials. Confirm also that the staging instance has every variable name from the inventory. Check the names again across the instances. The step is done when the workflow is present in staging and every referenced variable name exists there.

  7. Test the promoted workflow in staging

    Run a test execution of the promoted workflow in staging. Open the execution data and confirm each expression resolved to a staging value, and that calls go to staging systems rather than production. Test any failure path that depends on a missing variable, so the error names the variable and does not fail silently. Keep the execution record with the change ticket. The step is done when the staging run uses only staging values and the team signs off before the workflow moves to production.

Keeping secrets and sensitive values out of variables

Variables are convenient for environment-specific settings, but they are not a secure store. The cards below cover where exposure happens, who can see values, and where credentials or an external vault are the safer home.

Tokens and passwords in variables

A variable is a plain value that workflows reference by name, so anything typed into one is available to every workflow that reads it. Treat variables as configuration only: hostnames, feature flags, queue names and project identifiers. API tokens, database passwords and signing keys belong somewhere that has encryption and per-user access controls. Before creating a variable, ask whether its value would be harmful if a broad group of editors read it.

Access control docs

Who can read variable values

Anyone with editor access to a project that can use a variable can usually see its value in the editor, and any principal able to call the public API with sufficient rights can read it there too. Access is therefore set by role and project membership rather than by the variable itself. Confirm with your own tests which roles see which variables on your edition, and review project membership before loading sensitive values.

Exports and Git commits expose values

Workflow exports and source-control commits carry variable definitions along with workflows when those variables are included in the sync scope. A value committed to a repository persists in Git history even after it is deleted from the file, and it reaches every clone and backup of that repository. Check what your environment sync actually transfers, and keep secret-bearing values out of the repository entirely.

Credentials as the safer home

Credentials are stored encrypted in the database and are referenced by workflows without exposing their contents in the workflow definition. Sharing can be limited to specific users or projects, which is the right model for API keys and OAuth connections. Confirm how credential data moves between instances, because the encryption key must match wherever credentials are decrypted.

External vault for shared secrets

When several systems or pipelines need the same secret, or when rotation and central audit matter more than convenience, a dedicated secrets manager is the stronger choice. Ask whether your n8n edition supports reading secrets from an external vault, and whether that integration is in your plan scope before designing around it. Plan rotation ownership and a revocation step for each secret.

Audit trail and access reviews

Secret handling is only defensible if you can show who changed a value and who had access to it. Enable audit logging where your edition provides it, export logs to your central system, and schedule periodic reviews of users and projects that can see sensitive configuration. Ask your vendor or partner to confirm which events are logged for variables and credentials before relying on them as evidence.

How variables travel with source control and what stays behind

Start by fixing the boundary between what Git holds and what each instance keeps. The source control feature exports a defined set of resources from an instance into the repository, and everything outside that set stays in the instance's own database. Live variable values, execution history and the encryption key that protects stored credentials are local to the instance, so a commit never carries a credential secret. Confirm on your version exactly which resource types the push and pull actions include, and whether variable values are written to the repository or only variable names and references. Your answer determines where each value must be managed, so settle it before you write any environment procedure.

Environment branches interact with variable values in a predictable way only if each branch maps to one instance. The development branch carries workflows that refer to variable names, while each instance resolves those names to its own values. Pulling a change into production does not copy development values into production, and it does not overwrite the production values either. Keep a per-instance value register that the release owner checks after each pull. If a value is ever committed to a branch by mistake, Git history retains it after the file is changed, so treat that as a secret exposure and rotate the value, not just a cleanup task.

A variable rename is the change most likely to break a running workflow. Any instance that pulls a workflow referencing the new name before the instance has the new variable will fail at run time. Put the rename in one pull request that lists every workflow referencing the old name, creates the new variable on each target instance first, and then changes the references. Run test executions of the affected workflows on staging, and remove the old name only after production executions succeed. Ask the vendor whether the platform validates variable references on import, and do not assume it does.

Questions teams ask before changing variables across environments

Does Git-backed environment setup for n8n variables need a paid plan?

Yes, the Git-backed environments feature is covered by a paid plan, so confirm the plan before you design the pipeline. n8n's pricing page says environments with Git are included only in the Business and Enterprise plans, and the Business plan is currently self-hosted only. The Community edition does not include this feature. Licensing also depends on what you run: the Sustainable Use License covers internal business use, and any file with .ee in its name needs a valid n8n Enterprise License. Start with the n8n pricing page, then confirm in writing with n8n which plan covers your exact feature set, because plan contents change over time.

What drives the cost of moving n8n variables between environments?

Most of the cost is engineering time. Someone must find every workflow that depends on environment-specific values, separate those values from the workflow logic, set them on each instance and test the result. The people paid for this work may be your own staff, a partner under a written scope, or both, and the n8n plan is a separate license cost. Setup is largely one-time, while changes to variables, new environments and reviews recur. Costs rise with:

  • The number of workflows that hard-code URLs, IDs or endpoints
  • The number of environments and separate instances
  • How many values are secrets that need credential handling
  • Whether source control and deployment pipelines already exist

When you request a quote, ask for an itemized scope that lists the workflows covered, the environments in scope, the naming convention to be delivered, the testing included and how later changes are handled.

How long does it take to set up n8n variables across environments?

There is no fixed duration until someone inventories your estate, so treat any number given without that inventory as a guess. The same drivers that shape cost also set time: how many workflows reference environment values, how many environments exist and how many secrets must move into credentials. A small setup with one or two instances and few workflows is a short exercise for an experienced n8n administrator. A large estate with many teams needs inventory, review and staged testing before production changes. Most DeployOpen engagements are fixed-scope, so the timeline is agreed in writing before work starts and tied to named deliverables. Ask for the timeline with its assumptions listed, including who approves changes and when production change windows are available.

Can our internal team handle n8n variables across environments alone?

Yes, an internal team can do this alone if it has the access and skills and the estate is small. Your team needs administrator access to each n8n instance, comfort with variable settings and either Git or a deployment process, and one person who owns the naming convention and sign-off. Internal teams usually manage a small estate of one or two instances with a modest number of workflows. The work gets harder when many workflows share logic, when secrets are spread across credentials or when you need evidence for an assessment. In those cases, a partner can work to a fixed scope. To decide, list your workflows, environments and approvals, then check whether your team has time to test each change in staging before it reaches production.

What do we need to provide before a variable migration starts?

Start with a complete picture of the current setup. Most engagements need four inputs:

  • An export or list of the workflows that run in each environment, with an owner for each
  • The list of n8n instances, where each is hosted and which plan each one runs on
  • Administrator access for the people doing the work, plus access to source control if you use it
  • Named approvers who confirm which values are production values and sign off on changes

Also list the external systems each workflow calls, because the values that differ between environments usually point to those systems. Confirm that matching test accounts exist in staging. Missing inputs tend to extend the work, so the written scope should state who provides each item and when it is due.

Should API keys and passwords live in n8n variables or credentials?

Store secrets in credentials and non-secret settings in variables. Credentials hold API keys, tokens and passwords, and they can be shared with users or projects without exposing the secret value. Variables suit base URLs, identifiers, feature flags and environment labels that workflows read at run time. Confirm in the n8n documentation for your version who can read variable values before you store anything sensitive there. In queue mode, every worker and webhook processor must share the main instance's encryption key to read stored credentials, so plan key handling together with credential setup. Test this on a staging instance before you move any production secrets.

Does source control carry n8n variable values between instances?

Do not assume it does. Confirm in the current n8n documentation which parts of an instance source control carries and which stay on the instance, because that answer shapes your pipeline. A common approach is to keep environment values out of the repository, reference variable names in workflows and set the values on each instance through a controlled step with its own review. Document the variable names in the repository so every environment expects the same keys. Test the pipeline on a nonproduction instance first, and check that a missing variable produces a clear failure during deployment.

What breaks when an n8n variable is missing or wrong in production?

A missing or wrong variable usually causes a workflow to fail, call the wrong system or write data to the wrong place. Wrong production values carry the most risk because they can send live customer or employee data to a test endpoint, or send test traffic to a live system. Reduce this with a naming convention checked in review, a staging run that uses staging values, approvals before production changes and alerts on failed executions. Set up failure monitoring before the first change, so the team learns about problems quickly. Ask any partner to show how they test variable changes and how they confirm that the production value set matches the approved list.

Limits to confirm in your own n8n environment

Variables look simple, but their behavior depends on your edition, your installed release and how your team moves workflows between instances. The cards below list the points to verify in your own environment before you build a promotion process around them.

Scopes available on your edition

Confirm which variable scopes your edition exposes, since global and project-level variables may not be available on every plan. The n8n pricing page separates Community, Starter, Pro, Business and Enterprise, and some environment features such as Git-based environments are limited to Business and Enterprise. Check the plan you run against the pricing page and the docs for your installed version, and test scope visibility with a user who has the role you plan to give your pipeline.

n8n pricing

Naming and value constraints

Confirm the allowed characters for variable names, the maximum length of names and values, and whether names are case sensitive in the release you run. Naming rules can change between releases, so a name that worked in staging may be rejected or behave differently after an upgrade. Write the rules into your internal naming standard and test a sample set of names in a non-production instance before you migrate values.

Behavior after upgrades

Confirm how existing variables, their values and their references are handled after you move to a new minor or major release. n8n ships minor releases frequently and uses semantic versioning, so a variable change may arrive without much notice. Read the release notes for each version between your current and target release, and run a post-upgrade check that lists every workflow referencing a variable and confirms it still resolves.

n8n release notes

Variables in packages and exports

Confirm whether variable references travel inside packages, JSON exports and source control pushes, and whether the variable values themselves are included. A workflow can carry a reference that the target instance cannot resolve, which causes failures only after promotion. Run one test package and one test export between two instances, then inspect the file contents for values you did not intend to copy.

Source control handling

Confirm whether variable definitions are pushed through source control or kept local to each instance, and how a pull affects values already set on the target. If the pull overwrites or ignores them, your staging and production values may drift. Document which side owns each variable, and check the behavior in a branch that you can reset, before any pipeline writes to a production instance.

Secrets that must stay in credentials

Confirm which values your team plans to store as variables and which must stay in credentials. Variables are not a secret store, and anyone with access to the variable screen or to a workflow expression may read their values. Check who can view variables in your edition and in your roles, then move API keys, tokens and passwords into credentials with restricted sharing before you finalize the variable list.

What a variables review covers in a DeployOpen engagement

A variables review starts with an inventory of every place a workflow refers to a value that changes between environments. DeployOpen walks the workflows in each instance and lists hard-coded hostnames, tenant identifiers, folder IDs, mailbox addresses, feature switches and endpoint URLs, then records which workflow, node and parameter uses each one. The output is a register that shows which values are already in custom variables, which are still typed into nodes, and which are secrets that currently sit in node parameters where they should not be. That register is the basis for every later decision, so it is the first deliverable the client reviews and signs off.

Next, each value is classified as either a variable or a credential, and the classification is written down with the reason. Non-secret configuration such as a base URL or a sender label usually goes into a variable, while passwords, API keys and OAuth tokens go into credentials that are shared per instance. DeployOpen then designs the naming scheme for variables, including prefixes by environment or system, case conventions and a rule for who may create a new name. The design is checked against the naming limits and the variable scope that your n8n version and plan actually support, so the team confirms those limits in its own instance before the names are fixed.

The last step tests promotion across instances. DeployOpen runs a pilot workflow through a development, staging and production copy, confirms that each variable resolves to the right value in each environment, and checks that no environment-specific value leaks back into source control. The test also records what a reviewer must do by hand after a package or Git pull, such as creating a missing variable on the target. Work is agreed in a fixed written scope that lists the workflows covered, the environments tested, the deliverables and the retest. Ask for a quote that names which of these items are included, and confirm with your team how many workflows and instances are in scope.

How DeployOpen scopes and supports n8n environment work

DeployOpen treats custom variables as part of the environment design, not as an afterthought. We scope which values move between development, staging and production, which stay in credentials, and how the variable set is documented and tested before workflows depend on it.

How we scope

  • Inventory every workflow value that changes between environments, such as hostnames, project identifiers and feature flags.
  • Agree which values become global or project variables and which must stay in credentials instead.
  • Confirm with your n8n plan and edition whether environments and source control features are available before design starts.

How we build

  • Define a naming convention for variables and check it against the naming limits that apply to your n8n version.
  • Configure variables per instance and test that workflows resolve the correct value in each environment.
  • Verify that no secret values appear in exported workflow JSON or in source control commits.

How we hand over

  • Deliver a variable register listing each name, purpose, owning team, and the environments where it is set.
  • Document the promotion steps so a change to a variable follows the same review path as a workflow change.
  • Walk your platform and automation teams through the runbook and record open items you need to confirm.

How we support

  • Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts.
  • Ongoing support, n8n upgrades and continuous testing are available as a retainer.
  • Retesting of variable and credential handling can follow each n8n upgrade or change to your source control setup.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.