Skip to main content

k6 archive

Create a fully self-contained test archive that can be executed identically elsewhere.

Synopsis

Description

The k6 archive command creates a tarball (.tar file) containing:
  • The test script
  • All imported modules and dependencies
  • Test configuration and options
  • Environment variables (unless excluded)
This archive is completely self-contained and can be executed on any system with k6 installed, ensuring consistent test execution across different environments.

Arguments

string
required
Path to the test script file to archive

Examples

Flags

string
default:"archive.tar"
Archive output filename. Use - to output to stdout.
boolean
Do not embed any environment variables (either from --env or the actual environment) in the archive metadata

Test Configuration Flags

All standard test execution flags are available to configure the archived test:
int
default:"1"
Number of virtual users
duration
Test duration
int
Total iteration limit
string[]
Add execution stages
string
Execution segment for distributed testing

Runtime Options

string[]
Add/override environment variable with VAR=value
boolean
Include system environment variables
string
default:"extended"
JavaScript compatibility mode
All other options from k6 run are also available. See k6 run for the complete list.

Archive Contents

A k6 archive contains:
  1. Test Script - The main JavaScript file
  2. Dependencies - All imported modules and files
  3. Configuration - Consolidated options from all sources
  4. Environment Variables - Runtime environment (unless excluded)
  5. Metadata - Version information and execution context

Use Cases

Reproducible Testing

Create an archive to ensure the exact same test can be run later:

Distributed Execution

Create archives for execution across multiple machines:

CI/CD Pipelines

Archive tests in one pipeline stage, execute in another:

Cloud Execution

Archives can be uploaded and executed in Grafana Cloud:

Security Considerations

By default, archives include environment variables. Use --exclude-env-vars if the archive will be shared or stored in version control.
Environment variables may contain sensitive information like:
  • API keys
  • Passwords
  • Tokens
  • Internal URLs
Always review what’s being archived when dealing with sensitive data.

Exit Codes

  • 0 - Archive created successfully
  • Non-zero - Error occurred

See Also