Skip to content

Commit 24a9c8c

Browse files
Merge pull request #3161 from OctopusDeploy/add-new-input-schema-examples
Add examples for RequiresApproval and feed validation in input schema
2 parents d8164ac + 0e3efd3 commit 24a9c8c

1 file changed

Lines changed: 65 additions & 1 deletion

File tree

  • src/pages/docs/platform-hub/policies

src/pages/docs/platform-hub/policies/schema.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The table below summarizes every top-level field available to your policies.
2828
| [Steps](#steps) | array | Yes | All steps included in the deployment process |
2929
| [SkippedSteps](#steps-and-skippedsteps) | array | Yes | IDs of any steps excluded from this deployment |
3030
| [Execution](#execution) | array | Yes | Execution order and parallelism settings for each step |
31-
| RequiresApproval | boolean | Yes | Whether the execution requires an [approval](/docs/approvals) |
31+
| [RequiresApproval](#requiresapproval) | boolean | Yes | Whether the execution requires an [approval](/docs/approvals) |
3232
| [Tenant](#tenant) | object | **No** | Present only for tenanted deployments |
3333
| [Release](#release) | object | **No** | Present only for deployments (not runbook runs) |
3434
| [Runbook](#runbook) | object | **No** | Present only for runbook runs (not deployments) |
@@ -95,6 +95,23 @@ The project group the project belongs to.
9595
| Name | string | The display name of the project group |
9696
| Slug | string | The URL-safe slug for the project group |
9797

98+
### RequiresApproval
99+
100+
Indicates whether an ITSM change approval is required for this deployment. Derived from the change control settings configured on the target project and environment.
101+
102+
**Example usage:**
103+
104+
```ruby
105+
package require_change_approvals
106+
107+
default result := { "allowed": false }
108+
109+
result := {
110+
"allowed": input.RequiresApproval,
111+
"reason": "No ITSM change request was found attached to this deployment or runbook run. Attach an approved change request, and try again.",
112+
}
113+
```
114+
98115
### Tenant
99116

100117
The tenant for tenanted deployments. **This field is absent for non-tenanted deployments.** Always guard against its absence before using it.
@@ -163,6 +180,7 @@ result := {"allowed": true} if {
163180
step.Source.SlugOrId == "<ActionTemplate-ID>"
164181
not step.Id in input.SkippedSteps
165182
step.Enabled == true
183+
step.IsConditional == false
166184
}
167185
```
168186

@@ -207,6 +225,52 @@ result := {"allowed": true} if {
207225
| Type | string | Yes | The feed type (e.g. `BuiltIn`, `Docker`) |
208226
| Uri | string | No | The configured endpoint for the feed |
209227

228+
**Example usage:**
229+
230+
```ruby
231+
package block_cross_environment_feeds
232+
233+
default result := {
234+
"allowed": true,
235+
"reason": "All packages use feeds appropriate for the target environment.",
236+
}
237+
238+
# Collect all packages across all steps
239+
all_packages contains pkg if {
240+
some step in input.Steps
241+
some pkg in step.Packages
242+
}
243+
244+
# Violation: dev feed used in production
245+
violations contains msg if {
246+
input.Environment.Slug == "prod"
247+
some pkg in all_packages
248+
contains(lower(pkg.Feed.Slug), "dev")
249+
msg := sprintf(
250+
"Non-compliant: Step '%s' uses dev feed '%s' but is deploying to Production.",
251+
[pkg.Id, pkg.Feed.Name],
252+
)
253+
}
254+
255+
# Violation: prod feed used in dev
256+
violations contains msg if {
257+
input.Environment.Slug == "dev"
258+
some pkg in all_packages
259+
contains(lower(pkg.Feed.Slug), "prod")
260+
msg := sprintf(
261+
"Step '%s' uses prod feed '%s' but is deploying to Dev.",
262+
[pkg.Id, pkg.Feed.Name],
263+
)
264+
}
265+
266+
result := {
267+
"allowed": false,
268+
"reason": concat(" ", violations),
269+
} if {
270+
count(violations) > 0
271+
}
272+
```
273+
210274
:::div{.hint}
211275

212276
See the [steps and skipping examples](/docs/platform-hub/policies/examples#check-that-a-step-isnt-skipped-in-a-deployment) for more patterns.

0 commit comments

Comments
 (0)