grafana/k6 · error
stack ID not configured
Error message
stack ID not configured
What it means
errMissingStackID is the second leg of checkCloudLoginFor: a token is configured but `conf.StackID` is unset or zero, so k6 has no stack to address cloud API calls against and refuses before any request. It is wrapped under the command's auth prefix together with the login advisory.
Source
Thrown at internal/cmd/cloud.go:40
"go.k6.io/k6/v2/internal/build"
cloudapiv6 "go.k6.io/k6/v2/internal/cloudapi/v6"
"go.k6.io/k6/v2/internal/ui/pb"
"go.k6.io/k6/v2/lib"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
const cloudRunAuthPrefix = "Running cloud tests requires auth settings"
var (
errCloudAuth = errors.New( //nolint:staticcheck // user-facing error message, capitalization is intentional
"Run `k6 cloud login` to authenticate, or check the docs for other options at" +
" https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication",
)
errMissingToken = errors.New("access token not configured")
errMissingStackID = errors.New("stack ID not configured")
// errNoProjectConfigured is returned by cloud sub-commands that require a
// concrete project to operate on when none can be resolved from the flags,
// the environment, or the logged-in configuration.
errNoProjectConfigured = errors.New(
"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project",
)
)
// checkCloudLogin verifies that both a token and a stack are configured.
// Together they represent a complete Grafana Cloud login.
func checkCloudLogin(conf cloudapi.Config) error {
return checkCloudLoginFor(conf, cloudRunAuthPrefix)
}
func checkCloudLoginFor(conf cloudapi.Config, prefix string) error {
if !conf.Token.Valid || conf.Token.String == "" {
return fmt.Errorf("%s: %w.\n%w", prefix, errMissingToken, errCloudAuth)View on GitHub (pinned to 94169daab2)
Solutions
- Run `k6 cloud login -t <token> --stack <stack-url-or-slug>` — the auth response resolves and stores the numeric stack ID
- In CI, additionally export K6_CLOUD_STACK_ID with the numeric stack ID shown in Grafana Cloud
- Inspect stored state with `k6 cloud login -s`; if stack-id shows <not set>, redo the login
- If you hand-maintain the config JSON, ensure both 'token' and 'stackID' keys exist under collectors.cloud
Example fix
# before export K6_CLOUD_TOKEN=glc_ey... k6 cloud run script.js # -> stack ID not configured # after export K6_CLOUD_TOKEN=glc_ey... export K6_CLOUD_STACK_ID=123456 k6 cloud run script.js
Defensive patterns
Strategy: validation
Validate before calling
: "${K6_CLOUD_TOKEN:?K6_CLOUD_TOKEN required}"
: "${K6_CLOUD_STACK_ID:?K6_CLOUD_STACK_ID required (numeric stack ID from Grafana Cloud)}"
case "$K6_CLOUD_STACK_ID" in ''|*[!0-9]*) echo 'K6_CLOUD_STACK_ID must be numeric'; exit 1;; esac Prevention
- Modern k6 needs token AND stack — prefer `k6 cloud login` over hand-editing config so both are stored consistently
- When migrating old token-only pipelines, add K6_CLOUD_STACK_ID in the same change
- Check `k6 cloud login -s` shows a numeric stack-id before wiring long-lived automation
When it happens
Trigger: Cloud commands when K6_CLOUD_TOKEN is set but K6_CLOUD_STACK_ID is not; or the config file contains a token but no stack-id — common when migrating from the legacy flow where only a token was needed, or when only the token key was hand-edited into the JSON config.
Common situations: CI pipelines built for older k6 versions (token-only auth) run against newer k6 requiring token+stack; users copying a token into config manually; logins made against a stack whose ID could not be resolved.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- access token not configured
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN m
- script name not set, please specify K6_CLOUD_NAME or options
- tests with unspecified duration are not allowed when outputt
- both K6_CLOUD_METRICS_PUSH_URL and K6_CLOUD_TEST_RUN_TOKEN m
AI-assisted analysis of grafana/k6@94169daab2 (2026-08-18).
Data as JSON: /api/errors/e4ddac92bdf02d5f.
Report an issue: GitHub.