Overview
There are four ways to provide variables:- Inline variables —
@var = valuein.httpfiles (same for all environments) - Config file —
hitspec.yamlwith anenvironmentssection (per-environment values) .envfiles — standard dotenv files injected with--env-file- 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:- Values are the same regardless of environment
- Secrets are visible in the test file
- Switching environments requires editing the file
Config File (hitspec.yaml)
Thehitspec.yaml config file combines global settings with per-environment
variable sets under the environments: key:
--env flag (defaults to dev):
hitspec.yamlhitspec.yml
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:
.env file uses standard KEY=VALUE format:
${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:$env() is an optional fallback used when the variable is unset.
In hitspec.yaml, use shell-style ${VAR} syntax instead:
HITSPEC_ Environment Variables
All major CLI flags can be set via environment variables with theHITSPEC_ 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):hitspec.yamlenvironment — values for the active--env- Inline variables —
@variable = valuein the.httpfile - Captured values —
{{requestName.captureName}}from prior responses
$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:
Use System Variables in CI/CD
- GitHub Actions
- Shell
Shared Base Configuration
Reuse YAML anchors inhitspec.yaml to share values across environments:
Environment-Specific Test Behavior
Drive timeouts, retry settings, and other behavioral differences from environment variables:Recommended Project Structure
Troubleshooting
Variable not found
Variable not found
- Check that
hitspec.yamldefines the variable under the active environment. - Verify the
--envflag matches an environment key:hitspec run tests/ --env dev. - Check for typos in variable names (they are case-sensitive).
Environment not found
Environment not found
- Add a
staging:key underenvironments:inhitspec.yaml. - Check for typos in the environment name.
System variable not set
System variable not set
- Export the variable:
export API_TOKEN=xxx - Set it inline:
API_TOKEN=xxx hitspec run tests/ - Pass it via a dotenv file:
hitspec run tests/ --env-file .env - In CI/CD, add it to your secrets and pass it to the workflow.
- Use a default value:
{{$env(API_TOKEN, fallback-value)}}