-
Notifications
You must be signed in to change notification settings - Fork 101
Add doc for environment state #3319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d499fa9
add doc for environment state
yangguoif 746257b
fix linting
yangguoif d52de1a
tweaks
yangguoif 99c3c18
Update src/pages/docs/infrastructure/environments/environment-state.md
yangguoif 569fb88
Update src/pages/docs/projects/ephemeral-environments/index.md
yangguoif 890413f
tweak wording
yangguoif 4f2de6d
tweaks based on second round suggestions
yangguoif 873163e
Tweak content in Availability
yangguoif 8e8b641
tweak wording
yangguoif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Binary file added
BIN
+145 KB
public/docs/projects/ephemeral-environments/ephemeral-environment-url.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions
135
src/pages/docs/infrastructure/environments/environment-state.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| --- | ||
| layout: src/layouts/Default.astro | ||
| pubDate: 2026-08-07 | ||
| modDate: 2026-08-08 | ||
| title: Environment state | ||
| navTitle: Environment state | ||
| description: Save key/value state during a deployment or runbook run, then read it back in later deployments and runs. | ||
| navOrder: 30 | ||
| --- | ||
|
|
||
| Environment state lets a deployment or [runbook](/docs/runbooks) run save key/value pairs scoped to the combination of project, environment, and optionally a tenant. Later deployments and runbook runs for the same project and environment can then read those values back. | ||
|
|
||
| Environment state is useful in scenarios where a value produced during one run needs to be reused later. A common example is provisioning and deprovisioning [ephemeral environments](/docs/infrastructure/ephemeral-environments). A provisioning runbook might create a Kubernetes namespace or an application URL that later deployments and the deprovisioning runbook depend on. Recording each value as environment state means Octopus stores it once, so every later run reads it directly instead of re-deriving the value. | ||
|
|
||
| Each state entry is scoped to project, environment, and optionally a tenant, so state isn't shared with other projects, environments, or tenants. Setting an entry with a key that already exists for the same project, environment, and tenant overwrites the previous value. | ||
|
|
||
| ## Setting environment state | ||
|
|
||
| Set state from a PowerShell or Bash [script step](/docs/deployments/custom-scripts) using the wrapper functions Octopus provides. | ||
|
|
||
| <details data-group="set-environment-state"> | ||
| <summary>PowerShell</summary> | ||
|
|
||
| ```powershell | ||
| Set-EnvironmentState -Key "namespace" -Value "webstore-pr-482" | ||
| ``` | ||
|
|
||
| </details> | ||
| <details data-group="set-environment-state"> | ||
| <summary>Bash</summary> | ||
|
|
||
| ```bash | ||
| set_environmentstate "namespace" "webstore-pr-482" | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ### Sensitive values | ||
|
|
||
| Mark a value as sensitive to store it encrypted at rest and mask it in task logs. Add the `-Sensitive` switch in PowerShell, or `-sensitive` as the third argument in Bash. | ||
|
|
||
| <details data-group="set-sensitive-environment-state"> | ||
| <summary>PowerShell</summary> | ||
|
|
||
| ```powershell | ||
| Set-EnvironmentState -Key "connectionString" -Value "Server=db;Password=s3cret" -Sensitive | ||
| ``` | ||
|
|
||
| </details> | ||
| <details data-group="set-sensitive-environment-state"> | ||
| <summary>Bash</summary> | ||
|
|
||
| ```bash | ||
| set_environmentstate "connectionString" "Server=db;Password=s3cret" -sensitive | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ## Using environment state | ||
|
|
||
| Octopus makes each state entry available as a [variable](/docs/projects/variables) named `Octopus.Environment.State[key]` in later deployment or runbook run, where `key` is the name you set. | ||
|
|
||
| Read it from a script: | ||
|
|
||
| <details data-group="consume-environment-state"> | ||
| <summary>PowerShell</summary> | ||
|
|
||
| ```powershell | ||
| $namespace = $OctopusParameters["Octopus.Environment.State[namespace]"] | ||
| ``` | ||
|
|
||
| </details> | ||
| <details data-group="consume-environment-state"> | ||
| <summary>Bash</summary> | ||
|
|
||
| ```bash | ||
| namespace=$(get_octopusvariable "Octopus.Environment.State[namespace]") | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ## Setting an environment URL | ||
|
|
||
| An environment URL is a type of environment state, but gets first-class support in Octopus. It is stored like any other environment state, and surfaced as a clickable link in the Octopus Web Portal and available from the API. | ||
|
|
||
| Set a URL with the `Set-EnvironmentUrl` (PowerShell) or `set_environmenturl` (Bash) function. The first argument is the key that names the URL, and the second is the URL itself. | ||
|
|
||
| <details data-group="environment-url"> | ||
| <summary>PowerShell</summary> | ||
|
|
||
| ```powershell | ||
| Set-EnvironmentUrl -Key "Store front" -Url "https://pr-123.example.com" | ||
| ``` | ||
|
|
||
| </details> | ||
| <details data-group="environment-url"> | ||
| <summary>Bash</summary> | ||
|
|
||
| ```bash | ||
| set_environmenturl "Store front" "https://pr-123.example.com" | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| URLs set this way show as clickable links on the [Ephemeral Environments](/docs/projects/ephemeral-environments#environment-urls) in the project, so anyone reviewing the environment can open the running app. | ||
|
|
||
| :::div{.hint} | ||
| A URL is a special kind of environment state, the key used must be unique across all state entries (including other URLs) for the same project, environment, and tenant. Reusing a key overwrites the value stored under it. | ||
| ::: | ||
|
|
||
| ### Getting URLs from the API | ||
|
|
||
| You can fetch the environment URLs from the API, which is useful for AI agents and scripts that need a link to the running app without reading the task log. Add an optional `tenantId` query parameter for [tenanted](/docs/tenants) runs. | ||
|
|
||
| ```text | ||
| GET /api/spaces/{spaceId}/projects/{projectId}/environments/{environmentId}/urls | ||
| ``` | ||
|
|
||
| The response is an array of name and URL pairs: | ||
|
|
||
| ```json | ||
| [ | ||
| { "Name": "Store front", "Url": "https://pr-123.example.com" } | ||
| ] | ||
| ``` | ||
|
|
||
| ## Availability | ||
|
|
||
| Environment state is rolling out to Octopus Cloud, and will be available to self-hosted customers from version `2026.3`. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tweaked the wording here to |
||
|
|
||
| ## Learn more | ||
|
|
||
| - [Ephemeral environments](/docs/infrastructure/ephemeral-environments) | ||
| - [Runbooks](/docs/runbooks) | ||
| - [System variables](/docs/projects/variables/system-variables) | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.