Skip to content

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

Open
justin-newman wants to merge 6 commits intoOctopusDeploy: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 intoOctopusDeploy:mainfrom
justin-newman:feat/update-variable-snapshots

Conversation

@justin-newman
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

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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.
Copy link
Copy Markdown
Contributor

@hnrkndrssn hnrkndrssn left a comment

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.

const (
FlagProject = "project"
FlagVersion = "version"
FlagAliasReleaseNumberLegacy = "releaseNumber"
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.

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.

Comment on lines +105 to +115
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()
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.

This functionality should be implemented in our go client so that it can be used in other scenarios than just the cli.

Comment on lines +125 to +135
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()
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.

This functionality should be implemented in our go client so that it can be used in other scenarios than just the cli.

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