Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/grafana/k6/llms.txt

Use this file to discover all available pages before exploring further.

Environment Variables

k6 supports configuration through environment variables, which provide an alternative to CLI flags and are particularly useful in CI/CD environments.

Precedence

Configuration sources are applied in this order (later overrides earlier):
  1. Script options (export const options = {})
  2. Configuration file (k6.json)
  3. Environment variables
  4. CLI flags (highest priority)

Runtime Environment Variables

K6_TYPE

K6_TYPE
string
Override test type detection.Values: js, archive
K6_TYPE=js k6 run test.txt

K6_INCLUDE_SYSTEM_ENV_VARS

K6_INCLUDE_SYSTEM_ENV_VARS
boolean
default:"false"
Pass system environment variables to the script runtime.
K6_INCLUDE_SYSTEM_ENV_VARS=true k6 run script.js

K6_COMPATIBILITY_MODE

K6_COMPATIBILITY_MODE
string
default:"extended"
JavaScript runtime compatibility mode.Values: extended, base, experimental_enhanced
K6_COMPATIBILITY_MODE=base k6 run script.js

Output and Summary Variables

K6_OUT

K6_OUT
string[]
Metrics output destinations (comma-separated).
K6_OUT="json=results.json,influxdb=http://localhost:8086" k6 run script.js

K6_NO_SUMMARY

K6_NO_SUMMARY
boolean
Disable the end-of-test summary.Deprecated: Use K6_SUMMARY_MODE=disabled instead.
K6_NO_SUMMARY=true k6 run script.js

K6_SUMMARY_MODE

K6_SUMMARY_MODE
string
default:"compact"
Summary display mode.Values: compact, full, disabled, legacy (deprecated)
K6_SUMMARY_MODE=full k6 run script.js

K6_SUMMARY_EXPORT

K6_SUMMARY_EXPORT
string
Export summary to a JSON file.
K6_SUMMARY_EXPORT=summary.json k6 run script.js

K6_NO_THRESHOLDS

K6_NO_THRESHOLDS
boolean
Disable threshold execution.
K6_NO_THRESHOLDS=true k6 run script.js

Test Execution Variables

K6_LINGER

K6_LINGER
boolean
Keep the API server alive after test completion.
K6_LINGER=true k6 run script.js

K6_NO_USAGE_REPORT

K6_NO_USAGE_REPORT
boolean
Disable anonymous usage statistics.
K6_NO_USAGE_REPORT=true k6 run script.js

K6_WEB_DASHBOARD

K6_WEB_DASHBOARD
boolean
Enable the web dashboard.
K6_WEB_DASHBOARD=true k6 run script.js

Tracing Variables

K6_TRACES_OUTPUT

K6_TRACES_OUTPUT
string
default:"none"
Distributed tracing output configuration.Values: none, otel, otel=host:port
K6_TRACES_OUTPUT=otel=localhost:4317 k6 run script.js

SSLKEYLOGFILE

SSLKEYLOGFILE
string
File to write TLS master secrets for decrypting traffic.
SSLKEYLOGFILE=/tmp/sslkeys.log k6 run script.js

Cloud Variables

K6_CLOUD_TOKEN

K6_CLOUD_TOKEN
string
Grafana Cloud k6 authentication token.
K6_CLOUD_TOKEN=your_token k6 cloud run script.js

K6_CLOUD_HOST

K6_CLOUD_HOST
string
default:"https://ingest.k6.io"
Grafana Cloud k6 API host.
K6_CLOUD_HOST=https://custom.k6.io k6 cloud run script.js

K6_CLOUD_PROJECT_ID

K6_CLOUD_PROJECT_ID
int
Project ID for organizing cloud tests.
K6_CLOUD_PROJECT_ID=12345 k6 cloud run script.js

K6_CLOUD_STACK_ID

K6_CLOUD_STACK_ID
int
Stack ID for Grafana Cloud instance.
K6_CLOUD_STACK_ID=12345 k6 cloud run script.js

K6_SHOW_CLOUD_LOGS

K6_SHOW_CLOUD_LOGS
boolean
default:"true"
Stream cloud test logs to terminal.
K6_SHOW_CLOUD_LOGS=false k6 cloud run script.js

K6_EXIT_ON_RUNNING

K6_EXIT_ON_RUNNING
boolean
Exit when cloud test reaches running state.
K6_EXIT_ON_RUNNING=true k6 cloud run script.js

K6_CLOUD_UPLOAD_ONLY

K6_CLOUD_UPLOAD_ONLY
boolean
Upload test to cloud without running it.Deprecated: Use k6 cloud upload instead.
K6_CLOUD_UPLOAD_ONLY=true k6 cloud script.js

K6_NO_ARCHIVE_UPLOAD

K6_NO_ARCHIVE_UPLOAD
boolean
Disable archive upload in cloud run commands.
K6_NO_ARCHIVE_UPLOAD=true k6 cloud run script.js

Global Variables

K6_ADDRESS

K6_ADDRESS
string
default:"localhost:6565"
REST API server address.
K6_ADDRESS=localhost:8080 k6 run script.js

K6_CONFIG

K6_CONFIG
string
default:"./k6.json"
Path to configuration file.
K6_CONFIG=/path/to/config.json k6 run script.js

K6_LOG_FORMAT

K6_LOG_FORMAT
string
default:"text"
Log output format.Values: text, json
K6_LOG_FORMAT=json k6 run script.js

K6_LOG_OUTPUT

K6_LOG_OUTPUT
string
default:"stderr"
Log output destination.Values: stderr, stdout, or file path
K6_LOG_OUTPUT=/var/log/k6.log k6 run script.js

K6_NO_COLOR

K6_NO_COLOR
boolean
Disable colored output.
K6_NO_COLOR=true k6 run script.js

K6_QUIET

K6_QUIET
boolean
Disable progress updates.
K6_QUIET=true k6 run script.js

K6_VERBOSE

K6_VERBOSE
boolean
Enable verbose logging.
K6_VERBOSE=true k6 run script.js

Script Environment Variables

Variables prefixed with K6_ are k6 configuration. To pass custom variables to your script:
# Set custom variables (not K6_ prefixed)
API_URL=https://api.example.com k6 run --include-system-env-vars script.js

# Or use -e flag
k6 run -e API_URL=https://api.example.com script.js
In your script:
export default function() {
  const apiUrl = __ENV.API_URL;
  console.log(apiUrl);
}

CI/CD Best Practices

Secrets Management

Never hardcode secrets in scripts:
# Good - use environment variables
K6_CLOUD_TOKEN=$SECRET_TOKEN k6 cloud run script.js

# Bad - token in script
export const options = {
  cloud: { token: 'hardcoded-token' }
};

Configuration Matrix

Use environment variables for test variants:
# Smoke test
VU_COUNT=1 DURATION=1m k6 run script.js

# Load test
VU_COUNT=100 DURATION=10m k6 run script.js

# Stress test
VU_COUNT=500 DURATION=30m k6 run script.js

Output Configuration

Configure outputs per environment:
# Development
K6_OUT=json=dev-results.json k6 run script.js

# Production
K6_OUT="influxdb=http://influxdb:8086,cloud" k6 run script.js

Boolean Values

Environment variables accept these boolean values: True: 1, t, T, true, TRUE, True False: 0, f, F, false, FALSE, False Example:
K6_NO_COLOR=1 k6 run script.js        # true
K6_NO_COLOR=true k6 run script.js     # true
K6_NO_COLOR=false k6 run script.js    # false

See Also

Build docs developers (and LLMs) love