> ## 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

> Environment variables supported by k6

# 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

<ParamField path="K6_TYPE" type="string">
  Override test type detection.

  **Values:** `js`, `archive`

  ```bash theme={null}
  K6_TYPE=js k6 run test.txt
  ```
</ParamField>

### K6\_INCLUDE\_SYSTEM\_ENV\_VARS

<ParamField path="K6_INCLUDE_SYSTEM_ENV_VARS" type="boolean" default="false">
  Pass system environment variables to the script runtime.

  ```bash theme={null}
  K6_INCLUDE_SYSTEM_ENV_VARS=true k6 run script.js
  ```
</ParamField>

### K6\_COMPATIBILITY\_MODE

<ParamField path="K6_COMPATIBILITY_MODE" type="string" default="extended">
  JavaScript runtime compatibility mode.

  **Values:** `extended`, `base`, `experimental_enhanced`

  ```bash theme={null}
  K6_COMPATIBILITY_MODE=base k6 run script.js
  ```
</ParamField>

## Output and Summary Variables

### K6\_OUT

<ParamField path="K6_OUT" type="string[]">
  Metrics output destinations (comma-separated).

  ```bash theme={null}
  K6_OUT="json=results.json,influxdb=http://localhost:8086" k6 run script.js
  ```
</ParamField>

### K6\_NO\_SUMMARY

<ParamField path="K6_NO_SUMMARY" type="boolean">
  Disable the end-of-test summary.

  **Deprecated:** Use `K6_SUMMARY_MODE=disabled` instead.

  ```bash theme={null}
  K6_NO_SUMMARY=true k6 run script.js
  ```
</ParamField>

### K6\_SUMMARY\_MODE

<ParamField path="K6_SUMMARY_MODE" type="string" default="compact">
  Summary display mode.

  **Values:** `compact`, `full`, `disabled`, `legacy` (deprecated)

  ```bash theme={null}
  K6_SUMMARY_MODE=full k6 run script.js
  ```
</ParamField>

### K6\_SUMMARY\_EXPORT

<ParamField path="K6_SUMMARY_EXPORT" type="string">
  Export summary to a JSON file.

  ```bash theme={null}
  K6_SUMMARY_EXPORT=summary.json k6 run script.js
  ```
</ParamField>

### K6\_NO\_THRESHOLDS

<ParamField path="K6_NO_THRESHOLDS" type="boolean">
  Disable threshold execution.

  ```bash theme={null}
  K6_NO_THRESHOLDS=true k6 run script.js
  ```
</ParamField>

## Test Execution Variables

### K6\_LINGER

<ParamField path="K6_LINGER" type="boolean">
  Keep the API server alive after test completion.

  ```bash theme={null}
  K6_LINGER=true k6 run script.js
  ```
</ParamField>

### K6\_NO\_USAGE\_REPORT

<ParamField path="K6_NO_USAGE_REPORT" type="boolean">
  Disable anonymous usage statistics.

  ```bash theme={null}
  K6_NO_USAGE_REPORT=true k6 run script.js
  ```
</ParamField>

### K6\_WEB\_DASHBOARD

<ParamField path="K6_WEB_DASHBOARD" type="boolean">
  Enable the web dashboard.

  ```bash theme={null}
  K6_WEB_DASHBOARD=true k6 run script.js
  ```
</ParamField>

## Tracing Variables

### K6\_TRACES\_OUTPUT

<ParamField path="K6_TRACES_OUTPUT" type="string" default="none">
  Distributed tracing output configuration.

  **Values:** `none`, `otel`, `otel=host:port`

  ```bash theme={null}
  K6_TRACES_OUTPUT=otel=localhost:4317 k6 run script.js
  ```
</ParamField>

### SSLKEYLOGFILE

<ParamField path="SSLKEYLOGFILE" type="string">
  File to write TLS master secrets for decrypting traffic.

  ```bash theme={null}
  SSLKEYLOGFILE=/tmp/sslkeys.log k6 run script.js
  ```
</ParamField>

## Cloud Variables

### K6\_CLOUD\_TOKEN

<ParamField path="K6_CLOUD_TOKEN" type="string">
  Grafana Cloud k6 authentication token.

  ```bash theme={null}
  K6_CLOUD_TOKEN=your_token k6 cloud run script.js
  ```
</ParamField>

### K6\_CLOUD\_HOST

<ParamField path="K6_CLOUD_HOST" type="string" default="https://ingest.k6.io">
  Grafana Cloud k6 API host.

  ```bash theme={null}
  K6_CLOUD_HOST=https://custom.k6.io k6 cloud run script.js
  ```
</ParamField>

### K6\_CLOUD\_PROJECT\_ID

<ParamField path="K6_CLOUD_PROJECT_ID" type="int">
  Project ID for organizing cloud tests.

  ```bash theme={null}
  K6_CLOUD_PROJECT_ID=12345 k6 cloud run script.js
  ```
</ParamField>

### K6\_CLOUD\_STACK\_ID

<ParamField path="K6_CLOUD_STACK_ID" type="int">
  Stack ID for Grafana Cloud instance.

  ```bash theme={null}
  K6_CLOUD_STACK_ID=12345 k6 cloud run script.js
  ```
</ParamField>

### K6\_SHOW\_CLOUD\_LOGS

<ParamField path="K6_SHOW_CLOUD_LOGS" type="boolean" default="true">
  Stream cloud test logs to terminal.

  ```bash theme={null}
  K6_SHOW_CLOUD_LOGS=false k6 cloud run script.js
  ```
</ParamField>

### K6\_EXIT\_ON\_RUNNING

<ParamField path="K6_EXIT_ON_RUNNING" type="boolean">
  Exit when cloud test reaches running state.

  ```bash theme={null}
  K6_EXIT_ON_RUNNING=true k6 cloud run script.js
  ```
</ParamField>

### K6\_CLOUD\_UPLOAD\_ONLY

<ParamField path="K6_CLOUD_UPLOAD_ONLY" type="boolean">
  Upload test to cloud without running it.

  **Deprecated:** Use `k6 cloud upload` instead.

  ```bash theme={null}
  K6_CLOUD_UPLOAD_ONLY=true k6 cloud script.js
  ```
</ParamField>

### K6\_NO\_ARCHIVE\_UPLOAD

<ParamField path="K6_NO_ARCHIVE_UPLOAD" type="boolean">
  Disable archive upload in cloud run commands.

  ```bash theme={null}
  K6_NO_ARCHIVE_UPLOAD=true k6 cloud run script.js
  ```
</ParamField>

## Global Variables

### K6\_ADDRESS

<ParamField path="K6_ADDRESS" type="string" default="localhost:6565">
  REST API server address.

  ```bash theme={null}
  K6_ADDRESS=localhost:8080 k6 run script.js
  ```
</ParamField>

### K6\_CONFIG

<ParamField path="K6_CONFIG" type="string" default="./k6.json">
  Path to configuration file.

  ```bash theme={null}
  K6_CONFIG=/path/to/config.json k6 run script.js
  ```
</ParamField>

### K6\_LOG\_FORMAT

<ParamField path="K6_LOG_FORMAT" type="string" default="text">
  Log output format.

  **Values:** `text`, `json`

  ```bash theme={null}
  K6_LOG_FORMAT=json k6 run script.js
  ```
</ParamField>

### K6\_LOG\_OUTPUT

<ParamField path="K6_LOG_OUTPUT" type="string" default="stderr">
  Log output destination.

  **Values:** `stderr`, `stdout`, or file path

  ```bash theme={null}
  K6_LOG_OUTPUT=/var/log/k6.log k6 run script.js
  ```
</ParamField>

### K6\_NO\_COLOR

<ParamField path="K6_NO_COLOR" type="boolean">
  Disable colored output.

  ```bash theme={null}
  K6_NO_COLOR=true k6 run script.js
  ```
</ParamField>

### K6\_QUIET

<ParamField path="K6_QUIET" type="boolean">
  Disable progress updates.

  ```bash theme={null}
  K6_QUIET=true k6 run script.js
  ```
</ParamField>

### K6\_VERBOSE

<ParamField path="K6_VERBOSE" type="boolean">
  Enable verbose logging.

  ```bash theme={null}
  K6_VERBOSE=true k6 run script.js
  ```
</ParamField>

## Script Environment Variables

Variables prefixed with `K6_` are k6 configuration. To pass custom variables to your script:

```bash theme={null}
# 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:

```javascript theme={null}
export default function() {
  const apiUrl = __ENV.API_URL;
  console.log(apiUrl);
}
```

## CI/CD Best Practices

### Secrets Management

Never hardcode secrets in scripts:

```bash theme={null}
# 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:

```bash theme={null}
# 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:

```bash theme={null}
# 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:

```bash theme={null}
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

* [CLI Options Reference](/cli/options)
* [Configuration File Format](/cli/configuration-file)
* [k6 run](/cli/run)
