Repository navigation
Description
Problem
k6 cloud run --local-execution behaves differently from k6 run --out cloud: it is seems to always create a GCk6 test run, even when K6_CLOUD_PUSH_REF_ID is set.
Details
Sample runs:
$ K6_CLOUD_PUSH_REF_ID=99999 K6_CLOUD_TOKEN=<...> k6 run --out cloud test.js
/\ Grafana /‾‾/
/\ / \ |\ __ / /
/ \/ \ | |/ / / ‾‾\
/ \ | ( | (‾) |
/ __________ \ |_|\_\ \_____/
execution: local
script: test.js
output: cloud (https://app.k6.io/runs/99999)
<...>I don't think app.k6.io is correct here (another bug?), but at least K6_CLOUD_PUSH_REF_ID is being noticed properly.
$ K6_CLOUD_PUSH_REF_ID=99999 K6_CLOUD_TOKEN=<...> k6 cloud run --local-execution test.js
WARN[0000] DEPRECATED: No stack specified. Consider setting a default stack via the `k6 cloud login` command or the `K6_CLOUD_STACK_ID` environment variable as this will become mandatory in the next major release.
/\ Grafana /‾‾/
/\ / \ |\ __ / /
/ \/ \ | |/ / / ‾‾\
/ \ | ( | (‾) |
/ __________ \ |_|\_\ \_____/
execution: local
script: test.js
output: cloud (https://<my stack>.grafana.net/a/k6-app/runs/7208258)
<...>
ERRO[0014] Failed to push metrics to the cloud error="(400/E5) Authentication error - could not authenticate (with read-access) to project the resource belongs to." output=cloudv2The test finishes locally but is not finalized on the Cloud: it waits for timeout there. It's not auth problem, because the same command and the same script is OK without K6_CLOUD_PUSH_REF_ID. So there is likely an internal mismatch of test run IDs.
LLM analysis on topic:
With k6 run --out cloud, K6_CLOUD_PUSH_REF_ID is respected in the cloud output's Start() method (internal/output/cloud/output.go:182-189): if PushRefID is valid, the output skips CreateTestRun and pushes metrics directly to the provided ref ID. It also skips finalization (output.go:290-291), deferring lifecycle management to the caller.
With k6 cloud run --local-execution, createCloudTest (internal/cmd/outputs_cloud.go:36) runs before the cloud output starts and unconditionally calls apiClient.CreateTestRun() (line 147) without checking K6_CLOUD_PUSH_REF_ID. This creates an orphaned test run every time.
The env var is bound via envconfig tag in cloudapi/config.go:41 and merged at config.go:136-137, so the config infrastructure already supports it — createCloudTest just doesn't use it.
This is blocking the move to the new command in k6-operator, issue.
Activity
Reranko05 commentedon Apr 7, 2026
Hi, I’d like to work on this issue.
Reranko05 commentedon Apr 8, 2026
Hi, I’ve opened a PR to address this issue: #5814
It ensures
K6_CLOUD_PUSH_REF_IDis respected ink6 cloud run --local-execution, aligning behavior withk6 run --out cloud.Would appreciate your feedback.