Environments
Manage different configurations for your flows and load tests using named environments. Switch between dev, staging, and prod with a single flag.
How Environments Work
Group-Level Environments
Each flow folder and spec folder has its own environments.json file. Environments are scoped to their group — a flow folder's environments are independent from a spec folder's environments.
-eUsing Environments
Select an Environment
Use -e / --env to select which environment to use.
# Run a flow with dev environment
tgrs run flow-folder -f my-flow -e dev
# Run a load test with staging environment
tgrs run spec-folder -s my-spec -e staging
# Run all flows/specs with prod environment
tgrs run folder-name -e prod
-e, tgrs will show an error listing the unresolved variables with a hint to use --env.Variable Types
Environment vs Flow Variables
{{varName}} — Environment Variables
Persistent data configured in the environment panel. Base URLs, API keys, credentials. Accessible via tg.environment.get() and tg.environment.set() in scripts. Available in both flows and load tests.
{{flow.varName}} — Flow Variables
Temporary data that carries between steps — tokens, IDs, response values. Not persisted. Designed to keep environments clean by separating runtime data from configuration. Accessible via tg.flow.get() and tg.flow.set() in scripts.
Example: Environment vs Flow Variables
Auth Flow — Why Both Matter
This example shows a typical auth flow where environment variables hold configuration and flow variables carry runtime data between steps.
Environment (persistent config)
{{base_url}} → https://api.example.com
1. beforeAllScript — Register a user
// Create a user with random data
var baseUrl = tg.environment.get("base_url");
var username = "{{random.string}}";
var password = "{{random.string}}";
var res = await fetch(baseUrl + "/register", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password })
});
// Store in flow vars — these change every run
tg.flow.set("username", username);
tg.flow.set("password", password);
2. Login Step — Use flow variables in body
URL: {{base_url}}/login
Body: {"username": "{{flow.username}}", "password": "{{flow.password}}"}
// Post-script: extract token from response
var data = tg.response.json();
tg.flow.set("token", data.token);
3. Subsequent Steps — Use token
URL: {{base_url}}/profile
Auth: Bearer {{flow.token}}
{{base_url}} is an environment variable — it stays the same across runs. {{flow.token}} is a flow variable — it changes every run because the user and token are random. Keep configuration in environments, keep runtime data in flow variables.How to Access Variables
Scripts vs Step Inputs
In Scripts (beforeAll, afterAll, pre-script, post-script)
Use the scripting API: tg.environment.get() / tg.environment.set() and tg.flow.get() / tg.flow.set()
In Step Inputs (URL, headers, body, params, auth)
Use placeholder syntax: {{varName}} for environment variables and {{flow.varName}} for flow variables
Variable Sources
Where Variables Come From
Each environment variable has a source that determines how its value is resolved.