{"record":{"id":"e4ddac92bdf02d5f","repo":"grafana/k6","slug":"stack-id-not-configured","errorCode":null,"errorMessage":"stack ID not configured","messagePattern":"stack ID not configured","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":40,"sourceCode":"\t\"go.k6.io/k6/v2/internal/build\"\n\tcloudapiv6 \"go.k6.io/k6/v2/internal/cloudapi/v6\"\n\t\"go.k6.io/k6/v2/internal/ui/pb\"\n\t\"go.k6.io/k6/v2/lib\"\n\n\t\"github.com/fatih/color\"\n\t\"github.com/spf13/cobra\"\n\t\"github.com/spf13/pflag\"\n)\n\nconst cloudRunAuthPrefix = \"Running cloud tests requires auth settings\"\n\nvar (\n\terrCloudAuth = errors.New( //nolint:staticcheck // user-facing error message, capitalization is intentional\n\t\t\"Run `k6 cloud login` to authenticate, or check the docs for other options at\" +\n\t\t\t\" https://grafana.com/docs/grafana-cloud/testing/k6/author-run/tokens-and-cli-authentication\",\n\t)\n\terrMissingToken   = errors.New(\"access token not configured\")\n\terrMissingStackID = errors.New(\"stack ID not configured\")\n\n\t// errNoProjectConfigured is returned by cloud sub-commands that require a\n\t// concrete project to operate on when none can be resolved from the flags,\n\t// the environment, or the logged-in configuration.\n\terrNoProjectConfigured = errors.New(\n\t\t\"no project specified. Use --project-id, set K6_CLOUD_PROJECT_ID, or run `k6 cloud login` to set a default project\",\n\t)\n)\n\n// checkCloudLogin verifies that both a token and a stack are configured.\n// Together they represent a complete Grafana Cloud login.\nfunc checkCloudLogin(conf cloudapi.Config) error {\n\treturn checkCloudLoginFor(conf, cloudRunAuthPrefix)\n}\n\nfunc checkCloudLoginFor(conf cloudapi.Config, prefix string) error {\n\tif !conf.Token.Valid || conf.Token.String == \"\" {\n\t\treturn fmt.Errorf(\"%s: %w.\\n%w\", prefix, errMissingToken, errCloudAuth)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/cloud.go#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\nexport K6_CLOUD_TOKEN=glc_ey...\nk6 cloud run script.js   # -> stack ID not configured\n\n# after\nexport K6_CLOUD_TOKEN=glc_ey...\nexport K6_CLOUD_STACK_ID=123456\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":": \"${K6_CLOUD_TOKEN:?K6_CLOUD_TOKEN required}\"\n: \"${K6_CLOUD_STACK_ID:?K6_CLOUD_STACK_ID required (numeric stack ID from Grafana Cloud)}\"\ncase \"$K6_CLOUD_STACK_ID\" in ''|*[!0-9]*) echo 'K6_CLOUD_STACK_ID must be numeric'; exit 1;; esac","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["k6","cloud","authentication","stack-id","configuration"],"backgroundTag":"missing-required-config","analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}