Preserve --variable values through interactive runbook run#606
Open
NickJosevski wants to merge 1 commit into
Open
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.
f47fe75 to
f2462ce
Compare
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.
Closes #582.
The bug
octopus runbook run -v Name:Valuesilently drops the variables in interactive mode — both from the printedAutomation Commandand from the actual run, which falls back to default values.--no-promptwas the workaround.Repro from #582:
The
Automation Commandcomes back missing both-vvalues:cause
The result map was rebuilt from the controls, not from the caller's inputs. Inside
askRunbookPreviewVariables(pkg/cmd/runbook/run/run.go), theresultmap was built fresh by iterating the form preview'sflattenedControls, only adding entries for controls. Any CLI-supplied variable without a matching control was discarded. The caller then overwroteoptions.Variableswith this stripped map.--no-promptskips 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(internalpackage 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
go test ./pkg/cmd/runbook/run/...runbook runcommand #582 .-vvalues are in both theAutomation Commandand the actual run.