fix: preserve --variable values through interactive runbook run#606
Open
NickJosevski wants to merge 1 commit into
Open
fix: preserve --variable values through interactive runbook run#606NickJosevski wants to merge 1 commit into
NickJosevski wants to merge 1 commit into
Conversation
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. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #582.
The bug
octopus runbook runwith--variable Name:Valueworks correctly under--no-prompt, but in interactive mode the-vvalues are silently dropped — both from the printedAutomation Commandand (per the reporter) from the actual run, which falls back to the prompted variables' default values.Reproduction from #582:
Output (note the missing
-vin the Automation Command):Workaround was passing
--no-promptexplicitly.Root cause
Inside
askRunbookPreviewVariables(pkg/cmd/runbook/run/run.go), theresultmap was built fresh by iterating over the form preview's controls (flattenedControls) and only adding entries for controls. Any CLI-supplied variable whose name didn't match a control was discarded. The caller then assigned this map back overoptions.Variables, losing the originals.--no-promptskips this codepath entirely, which is why the workaround works.Fix
Extract the variable-resolution logic into a pure helper,
resolveRunbookPreviewVariables, and seed the result map with the caller-supplied CLI variables before processing controls. Variables that 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.Tests
Added
pkg/cmd/runbook/run/preview_variables_test.go(internalpackage run) covering:Notes
pkg/cmd/release/deploy/deploy.goaround line 854. Not changed in this PR to keep the scope to the reported issue; happy to follow up.go testwasn't run in the environment this was authored in (no Go toolchain). Relying on CI to verify.Test plan
go test ./pkg/cmd/runbook/run/...including the new unit tests.runbook runcommand #582: run the original command interactively and confirm both the Automation Command output and the actual run carry the-vvalues.--no-promptpath is unaffected by running an existing automation-mode invocation.askRunbookPreviewVariablesis shared between DB and Git runbooks).🤖 Generated with Claude Code