{"record":{"id":"b0aa8e806f8fd761","repo":"grafana/k6","slug":"run-k6-cloud-login-to-authenticate-or-check-the","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cmd/cloud.go","lineNumber":35,"sourceCode":"\n\t\"go.k6.io/k6/v2/cloudapi\"\n\t\"go.k6.io/k6/v2/cmd/state\"\n\t\"go.k6.io/k6/v2/errext\"\n\t\"go.k6.io/k6/v2/errext/exitcodes\"\n\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)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/grafana/k6/blob/94169daab29df52c1ed2ee0549657a577666b855/internal/cmd/cloud.go#L17-L53","documentation":"errCloudAuth is the advisory tail of the composite error built by checkCloudLoginFor (internal/cmd/cloud.go:56-64): when a cloud command finds no token or no stack ID, k6 wraps errMissingToken/errMissingStackID together with this pointer to run `k6 cloud login`. Seeing this message means the cloud credentials in the consolidated config (disk config file + environment) are incomplete.","triggerScenarios":"Running `k6 cloud run script.js`, `k6 cloud upload`, `k6 cloud project list`, or `k6 cloud test list` when either the token (K6_CLOUD_TOKEN / config file) or the stack ID (K6_CLOUD_STACK_ID / config file) is missing; it is chained via %w under the 'Running cloud tests requires auth settings' prefix (or the command-specific prefix).","commonSituations":"Fresh install with no login yet; CI runners that export K6_CLOUD_TOKEN but forget K6_CLOUD_STACK_ID; running `k6 cloud login -r` (reset) and then a cloud command; config file at a non-default K6_CONFIG path that lacks the cloud section.","solutions":["Run `k6 cloud login -t <API_TOKEN> --stack <stack-url-or-slug>` once — it validates and stores token, stack ID, and default project","For CI/headless use, export both K6_CLOUD_TOKEN and K6_CLOUD_STACK_ID environment variables","Run `k6 cloud login -s` to inspect what is currently stored and spot the missing field","If you use a custom config file, confirm K6_CONFIG points at it and it contains the cloud collector entries"],"exampleFix":"# before\nexport K6_CLOUD_TOKEN=glc_ey...\nk6 cloud run script.js   # fails: stack ID not configured\n\n# after\nk6 cloud login -t glc_ey... --stack my-team\nk6 cloud run script.js","handlingStrategy":"validation","validationCode":"# shell/CI: verify a complete login before any cloud command\nk6 cloud login -s | grep -q 'token: <not set>' && { echo 'k6 token missing'; exit 1; }\nk6 cloud login -s | grep -q 'stack-id: <not set>' && { echo 'k6 stack missing'; exit 1; }","typeGuard":null,"tryCatchPattern":"k6 cloud run script.js || {\n  code=$?\n  echo \"k6 cloud failed (exit $code) - check auth config: run 'k6 cloud login'\" >&2\n  exit $code\n}","preventionTips":["Provision CI images with `k6 cloud login -t $K6_CLOUD_TOKEN --stack $K6_STACK` as a setup step","Store both K6_CLOUD_TOKEN and K6_CLOUD_STACK_ID as secrets together — one without the other always fails","After `k6 cloud login -r` (reset), remember the next cloud command will hit the auth check until you log in again"],"tags":["k6","cloud","authentication","login","grafana-cloud"],"backgroundTag":"missing-credentials","analyzedSha":"94169daab29df52c1ed2ee0549657a577666b855","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}