Skip to content

Preserve --variable values through interactive runbook run#606

Open
NickJosevski wants to merge 1 commit into
mainfrom
nj/issue-582
Open

Preserve --variable values through interactive runbook run#606
NickJosevski wants to merge 1 commit into
mainfrom
nj/issue-582

Conversation

@NickJosevski
Copy link
Copy Markdown
Contributor

@NickJosevski NickJosevski commented May 22, 2026

Closes #582.

The bug

octopus runbook run -v Name:Value silently drops the variables in interactive mode — both from the printed Automation Command and from the actual run, which falls back to default values. --no-prompt was the workaround.

Repro from #582:

octopus runbook run -p "New Project" -n "Runbook" -s "Kenny" -v "certCommonName:CLI" -v "prompt:CLI" -e "Development"

The Automation Command comes back missing both -v values:

Automation Command: octopus runbook run --project 'New Project' --name 'Runbook' --environment 'Development' --no-prompt

cause

The result map was rebuilt from the controls, not from the caller's inputs. Inside askRunbookPreviewVariables (pkg/cmd/runbook/run/run.go), the result map was built fresh by iterating the form preview's flattenedControls, only adding entries for controls. Any CLI-supplied variable without a matching control was discarded. The caller then overwrote options.Variables with this stripped map.

--no-prompt skips this codepath entirely — that's why the workaround works.

Fix

Extract the variable-resolution into a pure helper resolveRunbookPreviewVariables, and seed the result map with the caller's CLI variables before processing controls. Variables matching a control are still canonicalised to the control's name (existing case-fixing behaviour preserved); variables without a matching control pass through unchanged.

Tests

New pkg/cmd/runbook/run/preview_variables_test.go (internal package run) with 6 unit tests: passthrough (the fix), casing canonicalisation, no-prompt-when-supplied, sensitive tracking, prompt-fires-for-missing-required, and a combination case.

Tests

Command-line --variable arguments to `octopus runbook run` were being
silently dropped when the user went through the interactive prompts
(without --no-prompt). Inside askRunbookPreviewVariables, the result
map was rebuilt from the form preview's controls only, so any CLI
variable whose name didn't match a control was discarded. The resulting
runbook run fell back to the prompted variables' default values and the
printed Automation Command was missing the -v args.

This change extracts the variable-resolution logic into a pure helper,
resolveRunbookPreviewVariables, and seeds the result map with the
caller-supplied CLI variables before processing controls. Variables
that do match a control are still canonicalised to the control's name
(preserving the prior case-fixing behaviour). Variables without a
matching control are now passed through unchanged.

Adds unit tests covering: passthrough of unmatched CLI vars,
canonicalisation of mismatched casing, no-prompt when CLI satisfies a
required control, sensitive-variable tracking, and the still-working
prompt path for unprovided required controls.

A similar pattern exists in pkg/cmd/release/deploy/deploy.go around
line 854; not changed here to keep this PR scoped to the reported bug.
@NickJosevski NickJosevski changed the title fix: preserve --variable values through interactive runbook run Preserve --variable values through interactive runbook run May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prompted variable value arguments are stripped from runbook run command

1 participant