grafana/k6 · error
parsing K6_EXIT_ON_RUNNING returned an error: %w
Error message
parsing K6_EXIT_ON_RUNNING returned an error: %w
What it means
The `k6 cloud` preRun hook parses K6_EXIT_ON_RUNNING with strconv.ParseBool and fails. As with K6_SHOW_CLOUD_LOGS, only Go-style boolean literals (1/t/true/0/f/false in any capitalization ParseBool accepts) are valid. The value is validated even when --exit-on-running overrides it, so a bad value always stops the command.
Source
Thrown at internal/cmd/cloud.go:146
// TODO: refactor (https://github.com/grafana/k6/issues/883)
//
// We deliberately parse the env variables, to validate for wrong
// values, even if we don't subsequently use them (if the respective
// CLI flag was specified, since it has a higher priority).
if showCloudLogsEnv, ok := c.gs.Env["K6_SHOW_CLOUD_LOGS"]; ok {
showCloudLogsValue, err := strconv.ParseBool(showCloudLogsEnv)
if err != nil {
return fmt.Errorf("parsing K6_SHOW_CLOUD_LOGS returned an error: %w", err)
}
if !cmd.Flags().Changed("show-logs") {
c.showCloudLogs = showCloudLogsValue
}
}
if exitOnRunningEnv, ok := c.gs.Env["K6_EXIT_ON_RUNNING"]; ok {
exitOnRunningValue, err := strconv.ParseBool(exitOnRunningEnv)
if err != nil {
return fmt.Errorf("parsing K6_EXIT_ON_RUNNING returned an error: %w", err)
}
if !cmd.Flags().Changed("exit-on-running") {
c.exitOnRunning = exitOnRunningValue
}
}
return nil
}
// TODO: split apart some more
//
//nolint:funlen,gocognit,cyclop
func (c *cmdCloud) run(cmd *cobra.Command, args []string) error {
test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig)
if err != nil {
return err
}
// It's important to NOT set the derived options back to the runnerView on GitHub (pinned to 93accf6570)
Solutions
- Set K6_EXIT_ON_RUNNING to true or false exactly
- Unset the variable if unused
- Prefer the --exit-on-running flag, while ensuring any env var present still parses
Example fix
# before export K6_EXIT_ON_RUNNING=on # after export K6_EXIT_ON_RUNNING=true
Defensive patterns
Strategy: validation
Validate before calling
if v, ok := os.LookupEnv("K6_EXIT_ON_RUNNING"); ok {
if _, err := strconv.ParseBool(v); err != nil {
log.Fatalf("K6_EXIT_ON_RUNNING=%q is not a valid bool (use true/false)", v)
}
} Type guard
func isValidK6Bool(v string) bool {
_, err := strconv.ParseBool(v)
return err == nil
} Prevention
- Use only true/false literals in k6 env vars
- Normalize boolean env values in CI templates before the k6 step
- Document accepted boolean literals for teams used to yes/no style flags
When it happens
Trigger: K6_EXIT_ON_RUNNING is set to something like 'yes', 'on', '1 ' (trailing space), or 'TRUE\'', which strconv.ParseBool rejects.
Common situations: Templates or CI variables that emit non-literal booleans; copy-pasted env blocks from tutorials using 'on'; secrets managers injecting values with surrounding whitespace.
Related errors
- parsing K6_SHOW_CLOUD_LOGS returned an error: %w
- Run `k6 cloud login` to authenticate, or check the docs for
- access token not configured
- no project specified. Use --project-id, set K6_CLOUD_PROJECT
- 104
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/bc425dd4619eb5c3.
Report an issue: GitHub.