Variable Scopes
Bruno supports six variable scopes, each with different use cases and lifetimes:Environment
Environment-specific values
Global Environment
Shared across all environments
Collection
Collection-wide variables
Folder
Folder-level variables
Request
Request-specific variables
Runtime
Temporary execution variables
Variable Precedence
When multiple scopes define the same variable, Bruno uses the following precedence order (highest to lowest):Runtime variables have the highest precedence and will override all other scopes.
Environment Variables
Environment variables are specific to each environment (dev, staging, production, etc.) and are the most commonly used variable type.Setting Environment Variables
- Via UI
- Via Scripts
- Click the environment dropdown
- Select “Configure”
- Add or edit variables
- Save changes
Persistent Variables
By default, variables set via scripts are temporary. Use thepersist option to save them permanently:
Global Environment Variables
Global environment variables are shared across all environments, useful for values that don’t change between dev/staging/production.Runtime Variables
Runtime variables are temporary and exist only during request execution. They have the highest precedence and are perfect for passing data between requests.Basic Usage
Passing Data Between Requests
1
Request 1: Login
2
Request 2: Get Profile
3
Request 3: Update Profile
Collection Variables
Collection variables are defined at the collection level and are available to all requests in the collection.In collection.bru
In Scripts
Folder Variables
Folder variables are inherited by all requests within a folder and its subfolders.Folder variables can only be read in scripts, not modified. Define them in folder configuration.
Request Variables
Request variables are specific to a single request and have the lowest precedence among regular variables.Variable Interpolation
Use{{variableName}} syntax to interpolate variables in requests:
In URLs
In Headers
In Body
Programmatic Interpolation
Process Environment Variables
Access system environment variables from your OS:Variable Naming Rules
Valid Names
Invalid Names
Advanced Patterns
Conditional Variables
Variable Transformations
Dynamic Variable Generation
Variable Cleanup
Common Patterns
Token Management
Token Management
Pagination
Pagination
Resource IDs
Resource IDs
Environment Detection
Environment Detection
Best Practices
1
Choose the Right Scope
- Use environment variables for environment-specific values (API keys, URLs)
- Use runtime variables for passing data between requests
- Use collection variables for shared constants
- Use global variables for truly universal values
2
Use Descriptive Names
3
Clean Up Sensitive Data
4
Document Variable Usage
Add comments explaining variable purposes and expected values:
Related Resources
Scripting
Master Bruno’s scripting capabilities
Environments
Configure and manage environments
Assertions
Test and validate API responses
Workflows
Build complex request sequences