Skip to main content
hitspec supports environment-specific configuration so you can run the same tests against different servers, credentials, and settings without modifying your test files.

Overview

There are four ways to provide variables:
  1. Inline variables@var = value in .http files (same for all environments)
  2. Config filehitspec.yaml with an environments section (per-environment values)
  3. .env files — standard dotenv files injected with --env-file
  4. System environment variables — accessed via {{$VAR}} or the $env() function
Per-environment variables live in hitspec.yaml under the environments: key. There is no separate JSON environment file — hitspec.yaml and .env files are the supported sources.

Inline Variables

Define variables directly in your test file:
This is simple but limited:
  • Values are the same regardless of environment
  • Secrets are visible in the test file
  • Switching environments requires editing the file
Inline variables are best for values that do not change between environments, such as API version paths or test data.

Config File (hitspec.yaml)

The hitspec.yaml config file combines global settings with per-environment variable sets under the environments: key:
Select the environment with the --env flag (defaults to dev):
Your test files reference variables without knowing which environment is active:
hitspec searches for config files in this order:
  1. hitspec.yaml
  2. hitspec.yml
You can also specify a config file explicitly:
Inside hitspec.yaml, environment values can reference OS environment variables with shell-style ${VAR} syntax — ideal for keeping secrets out of the file and injecting them from CI secrets.

.env Files

Pass a standard dotenv file with the --env-file flag to inject additional variables:
The .env file uses standard KEY=VALUE format:
These values are exported to the process environment, so they’re available via ${VAR} in hitspec.yaml and via {{$VAR}} / {{$env(VAR)}} in your requests.

System Environment Variables

Reference system environment variables in your test files. Two forms are supported:
The second argument to $env() is an optional fallback used when the variable is unset.
The dotted form {{$env.VAR}} is not supported. Use {{$VAR}} or {{$env(VAR)}}.
In hitspec.yaml, use shell-style ${VAR} syntax instead:

HITSPEC_ Environment Variables

All major CLI flags can be set via environment variables with the HITSPEC_ prefix, which is useful in CI/CD pipelines:

Variable Resolution Order

When the same variable name comes from multiple sources, hitspec resolves it in this order (later sources override earlier ones):
  1. hitspec.yaml environment — values for the active --env
  2. Inline variables@variable = value in the .http file
  3. Captured values{{requestName.captureName}} from prior responses
Built-in functions ($uuid(), $timestamp(), $env(), …) and system variables ({{$VAR}}) are evaluated wherever they appear.
Inline variables override hitspec.yaml environment values. A @baseUrl = ... in your .http file takes precedence over the baseUrl defined for the active environment — remove the inline definition when you want environment-specific values to apply.

Best Practices

Keep Secrets Out of Version Control

Keep secrets in a .env file (or your CI secret store) and reference them with ${VAR} in hitspec.yaml, rather than committing tokens. Add the .env file to .gitignore:
Commit a template instead:

Use System Variables in CI/CD

Shared Base Configuration

Reuse YAML anchors in hitspec.yaml to share values across environments:

Environment-Specific Test Behavior

Drive timeouts, retry settings, and other behavioral differences from environment variables:

Troubleshooting

  1. Check that hitspec.yaml defines the variable under the active environment.
  2. Verify the --env flag matches an environment key: hitspec run tests/ --env dev.
  3. Check for typos in variable names (they are case-sensitive).
  1. Add a staging: key under environments: in hitspec.yaml.
  2. Check for typos in the environment name.
  1. Export the variable: export API_TOKEN=xxx
  2. Set it inline: API_TOKEN=xxx hitspec run tests/
  3. Pass it via a dotenv file: hitspec run tests/ --env-file .env
  4. In CI/CD, add it to your secrets and pass it to the workflow.
  5. Use a default value: {{$env(API_TOKEN, fallback-value)}}
Last modified on June 16, 2026