feat: add update-variables commands for releases and runbook snapshots - #589
feat: add update-variables commands for releases and runbook snapshots#589justin-newman wants to merge 11 commits into
Conversation
Adds two new commands that refresh variable snapshots in-place via POST to the Octopus Deploy snapshot-variables endpoint, replacing the need for manual PowerShell/REST calls: - `octopus release update-variables --project <p> --version <v>` - `octopus runbook snapshot update-variables --project <p> --runbook <r> [--snapshot <s>]` The runbook command defaults to the published snapshot when --snapshot is omitted; the release command targets the release directly by version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds new CLI subcommands to refresh (“re-snapshot”) variables on existing Octopus releases and runbook snapshots by calling the Octopus Server snapshot-variables endpoints, reducing the need for manual REST/PowerShell steps.
Changes:
- Add
octopus release update-variablesto POST/api/{spaceId}/releases/{releaseId}/snapshot-variables. - Add
octopus runbook snapshot update-variablesto POST/api/{spaceId}/runbookSnapshots/{snapshotId}/snapshot-variables(defaulting to the published snapshot). - Wire both commands into their respective parent command groups.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| pkg/cmd/release/update_variables/update_variables.go | Implements release update-variables command, including interactive prompting and POST call to refresh the release variable snapshot. |
| pkg/cmd/release/release.go | Registers the new release update-variables subcommand. |
| pkg/cmd/runbook/snapshot/update_variables/update_variables.go | Implements runbook snapshot update-variables command, including snapshot resolution and POST call to refresh the runbook snapshot variable snapshot. |
| pkg/cmd/runbook/snapshot/snapshot.go | Registers the new runbook snapshot update-variables subcommand. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ariable snapshot When the updateVariables call returned a non-2xx status the code previously ignored errors from io.ReadAll and could lose the underlying read error. Now read errors are checked and returned with a descriptive message including the HTTP status code.
… update-variables When updating runbook variable snapshots, return whether the published snapshot was used and print a notice showing the snapshot name/ID. Improve success output to include snapshot ID and runbook name. Also ensure errors from helper lookups (project/runbook) are propagated immediately rather than returned alongside a nil value. These changes clarify behavior when --snapshot is omitted and tighten error handling.
…mands Add comprehensive tests for the new "update-variables" commands: - pkg/cmd/release/update_variables/update_variables_test.go - pkg/cmd/runbook/snapshot/update_variables/update_variables_test.go Tests cover interactive and no-prompt flows, project/runbook lookup behavior, handling of published vs. explicit runbook snapshots, successful POST to snapshot-variables, and error responses (including non-2xx status bodies). These tests help validate CLI prompts, automation command output, and error propagation for the update-variables functionality.
…ables and add no-prompt tests Return clear errors when required flags are missing (project/version for release, project/runbook for runbook snapshot) and add corresponding no-prompt tests to ensure the CLI fails fast with a helpful message.
hnrkndrssn
left a comment
There was a problem hiding this comment.
Thanks @justin-newman for your contribution, I've left some comments for your attention.
Replace the hand-rolled HTTP POST to /snapshot-variables with a call to releases.SnapshotVariables from the go-octopusdeploy client, removing direct net/http and io usage from the command. Update tests to reflect that success responses are now decoded into a Release and error bodies are decoded into core.APIError.
…riables Delegate the snapshot-variables HTTP call to runbooks.SnapshotVariables in the go client instead of hand-rolling http.NewRequest/DoRawRequest. Also fixes pre-existing test-mock defects that meant these tests never passed: - runbook-lookup 404s now return a non-empty body; an empty-body 404 is swallowed by newclient's ContentLength==0 short-circuit, so GetByID returned an empty runbook with no error and the GetByID->GetByName fallback never fired. - runbook partialName query now expects %20 (newclient/uritemplates encoding), not + (which only the old sling-based project lookups produce). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kxy5kq5bnADFFMi8W4NqXX
|
Thanks for the review, @hnrkndrssn. Here's how I'm addressing the feedback: 1. Legacy 2. / 3.
Each follows the existing package conventions (validate, expand Client PR: OctopusDeploy/go-octopusdeploy#430 Ordering: this PR depends on #430. Once #430 merges and a version is tagged, I'll bump the |
|
any follow-up on this @hnrkndrssn? |
Hey @justin-newman my sincere apologies, I've not been able to get back to this PR yet. I will make time for it today and get sure to get it reviewed and any feedback I have to you. 🙏 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
pkg/cmd/release/update_variables/update_variables.go:160
- When
--projectis provided in interactive mode,selectors.FindProjectmay return(nil, nil)if the project isn't found; the current code then passes a nil project into release selection. Also,shared.SelectReleasehardcodes "Progression" into the prompt text, which is confusing for an update-variables operation. Add a nil check and select from release versions with a task-appropriate prompt.
selectedProject, err = selectors.FindProject(opts.Client, opts.Project.Value)
if err != nil {
return err
}
}
if opts.Version.Value == "" {
selectedRelease, err := shared.SelectRelease(opts.Client, selectedProject, opts.Ask, "Update Variables for")
if err != nil {
return err
}
opts.Version.Value = selectedRelease.Version
}
…client UpdateSnapshotVariables Rename the release and runbook snapshot commands/packages from update-variables to snapshot-variables, update flags/types/command names and tests accordingly, and switch the command implementations to call the go-client's UpdateSnapshotVariables helper. Also add explicit "project not found" validation where projects could be nil to return a clear error when lookups fail.
Summary
octopus release update-variables— refreshes the variable snapshot on an existing release by POSTing to/api/{spaceId}/releases/{releaseId}/snapshot-variablesoctopus runbook snapshot update-variables— refreshes the variable snapshot on an existing runbook snapshot (defaults to the published snapshot) by POSTing to/api/{spaceId}/runbookSnapshots/{id}/snapshot-variablesBoth commands replace the need for manual PowerShell/REST calls to update variable snapshots, support interactive prompts and
--no-promptautomation mode, and emit a deep link and automation command on success.Usage
Test plan
octopus release update-variables -p <project> -v <version>against a real server — confirm variables refreshed in Octopus UIoctopus runbook snapshot update-variables -p <project> -r <runbook>— confirm published snapshot variables refreshedoctopus runbook snapshot update-variables -p <project> -r <runbook> --snapshot <name>— confirm named snapshot updated--no-promptmode with all flags — no interactive prompts, no automation command printed--no-promptmode — clear error returned--snapshotflag — error message guides user