Skip to content

feat: add update-variables commands for releases and runbook snapshots#589

Open
justin-newman wants to merge 6 commits into
OctopusDeploy:mainfrom
justin-newman:feat/update-variable-snapshots
Open

feat: add update-variables commands for releases and runbook snapshots#589
justin-newman wants to merge 6 commits into
OctopusDeploy:mainfrom
justin-newman:feat/update-variable-snapshots

Conversation

@justin-newman

@justin-newman justin-newman commented Apr 15, 2026

Copy link
Copy Markdown

Summary

  • Adds octopus release update-variables — refreshes the variable snapshot on an existing release by POSTing to /api/{spaceId}/releases/{releaseId}/snapshot-variables
  • Adds octopus 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-variables

Both commands replace the need for manual PowerShell/REST calls to update variable snapshots, support interactive prompts and --no-prompt automation mode, and emit a deep link and automation command on success.

Usage

# Release
octopus release update-variables -p MyProject -v 1.2.3

# Runbook snapshot (published snapshot)
octopus runbook snapshot update-variables -p MyProject -r "Restart App"

# Runbook snapshot (specific snapshot)
octopus runbook snapshot update-variables -p MyProject -r "Restart App" --snapshot "Snapshot 40C9ENM"

Test plan

  • octopus release update-variables -p <project> -v <version> against a real server — confirm variables refreshed in Octopus UI
  • octopus runbook snapshot update-variables -p <project> -r <runbook> — confirm published snapshot variables refreshed
  • octopus runbook snapshot update-variables -p <project> -r <runbook> --snapshot <name> — confirm named snapshot updated
  • --no-prompt mode with all flags — no interactive prompts, no automation command printed
  • Missing required flags in --no-prompt mode — clear error returned
  • Runbook with no published snapshot and no --snapshot flag — error message guides user

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-variables to POST /api/{spaceId}/releases/{releaseId}/snapshot-variables.
  • Add octopus runbook snapshot update-variables to 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.

Comment thread pkg/cmd/release/update_variables/update_variables.go
Comment thread pkg/cmd/runbook/snapshot/update_variables/update_variables.go
Comment thread pkg/cmd/runbook/snapshot/update_variables/update_variables.go Outdated
Comment thread pkg/cmd/release/update_variables/update_variables.go
Comment thread pkg/cmd/release/update_variables/update_variables.go Outdated
justin-newman and others added 5 commits April 27, 2026 15:07
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 hnrkndrssn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @justin-newman for your contribution, I've left some comments for your attention.

Comment thread pkg/cmd/release/update_variables/update_variables.go
Comment thread pkg/cmd/release/update_variables/update_variables.go
Comment thread pkg/cmd/runbook/snapshot/update_variables/update_variables.go
@justin-newman

Copy link
Copy Markdown
Author

Thanks for the review, @hnrkndrssn. Here's how I'm addressing the feedback:

1. Legacy releaseNumber alias: removed. Agreed it doesn't belong on a brand-new command.

2. / 3. snapshot-variables should live in the go client: done. I've added two additive package functions to go-octopusdeploy:

  • releases.SnapshotVariables(client, spaceID, releaseID) maps to POST /releases/{id}/snapshot-variables
  • runbooks.SnapshotVariables(client, spaceID, snapshotID) maps to POST /runbookSnapshots/{id}/snapshot-variables

Each follows the existing package conventions (validate, expand uritemplates, call newclient.Post), mirroring GetReleaseDeploymentTemplate and GetSnapshot respectively. Both CLI commands now delegate to these instead of hand-rolling http.NewRequest/DoRawRequest.

Client PR: OctopusDeploy/go-octopusdeploy#430

Ordering: this PR depends on #430. Once #430 merges and a version is tagged, I'll bump the go-octopusdeploy dependency here, drop the temporary local replace, and push the refactor commits, at which point this is ready for another look.

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.

3 participants