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 6 commits intoOctopusDeploy:mainfrom
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.
| const ( | ||
| FlagProject = "project" | ||
| FlagVersion = "version" | ||
| FlagAliasReleaseNumberLegacy = "releaseNumber" |
There was a problem hiding this comment.
As this is a new command that has not previously existed, there's no need for a "legacy" alias.
The "legacy" aliases were added for backwards compatibility with commands that existed in the old .NET CLI.
| path := fmt.Sprintf("/api/%s/releases/%s/snapshot-variables", opts.Client.GetSpaceID(), releaseID) | ||
| req, err := http.NewRequest(http.MethodPost, path, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| resp, err := opts.Client.HttpSession().DoRawRequest(req) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer resp.Body.Close() |
There was a problem hiding this comment.
This functionality should be implemented in our go client so that it can be used in other scenarios than just the cli.
| path := fmt.Sprintf("/api/%s/runbookSnapshots/%s/snapshot-variables", opts.Space.GetID(), snapshotID) | ||
| req, err := http.NewRequest(http.MethodPost, path, nil) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| resp, err := opts.Client.HttpSession().DoRawRequest(req) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer resp.Body.Close() |
There was a problem hiding this comment.
This functionality should be implemented in our go client so that it can be used in other scenarios than just the cli.
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🤖 Generated with Claude Code