Skip to content

Commit 0dc7bfd

Browse files
Add deployment freeze override flags (#463)
* Add deployment freeze override flags * Change flag name to singular * Update client version
1 parent 788a9a3 commit 0dc7bfd

File tree

5 files changed

+95
-66
lines changed

5 files changed

+95
-66
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/AlecAivazis/survey/v2 v2.3.7
77
github.com/MakeNowJust/heredoc/v2 v2.0.1
88
github.com/OctopusDeploy/go-octodiff v1.0.0
9-
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.3
9+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.4
1010
github.com/bmatcuk/doublestar/v4 v4.4.0
1111
github.com/briandowns/spinner v1.19.0
1212
github.com/google/uuid v1.3.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ github.com/OctopusDeploy/go-octodiff v1.0.0 h1:U+ORg6azniwwYo+O44giOw6TiD5USk8S4
4848
github.com/OctopusDeploy/go-octodiff v1.0.0/go.mod h1:Mze0+EkOWTgTmi8++fyUc6r0aLZT7qD9gX+31t8MmIU=
4949
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.3 h1:qZfyylXCIXPKRwUwG3fsyhubQblKZBfxphQDJg5Uf/k=
5050
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.3/go.mod h1:ZCOnCz9ae/uuOk7AIQ9NzjnzFbuN8Q7H3oj2Eq4QSgQ=
51+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.4 h1:2y0wbmPT5D1MD2Xvyme0GZXkGF41Y9J84HP5PKkUEQI=
52+
github.com/OctopusDeploy/go-octopusdeploy/v2 v2.65.4/go.mod h1:ZCOnCz9ae/uuOk7AIQ9NzjnzFbuN8Q7H3oj2Eq4QSgQ=
5153
github.com/bmatcuk/doublestar/v4 v4.4.0 h1:LmAwNwhjEbYtyVLzjcP/XeVw4nhuScHGkF/XWXnvIic=
5254
github.com/bmatcuk/doublestar/v4 v4.4.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
5355
github.com/briandowns/spinner v1.19.0 h1:s8aq38H+Qju89yhp89b4iIiMzMm8YN3p6vGpwyh/a8E=

pkg/cmd/release/deploy/deploy.go

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ const (
8282

8383
FlagUpdateVariables = "update-variables"
8484
FlagAliasUpdateVariablesLegacy = "updateVariables"
85+
86+
FlagDeploymentFreezeName = "deployment-freeze-name"
87+
FlagDeploymentFreezeOverrideReason = "deployment-freeze-override-reason"
8588
)
8689

8790
// executions API stops here.
@@ -90,38 +93,42 @@ const (
9093
// DESIGN CHOICE: We are not going to show servertask progress in the CLI.
9194

9295
type DeployFlags struct {
93-
Project *flag.Flag[string]
94-
ReleaseVersion *flag.Flag[string] // the release to deploy
95-
Environments *flag.Flag[[]string] // multiple for untenanted deployment
96-
Tenants *flag.Flag[[]string]
97-
TenantTags *flag.Flag[[]string]
98-
DeployAt *flag.Flag[string]
99-
MaxQueueTime *flag.Flag[string]
100-
Variables *flag.Flag[[]string]
101-
UpdateVariables *flag.Flag[bool]
102-
ExcludedSteps *flag.Flag[[]string]
103-
GuidedFailureMode *flag.Flag[string] // tri-state: true, false, or "use default". Can we model it with an optional bool?
104-
ForcePackageDownload *flag.Flag[bool]
105-
DeploymentTargets *flag.Flag[[]string]
106-
ExcludeTargets *flag.Flag[[]string]
96+
Project *flag.Flag[string]
97+
ReleaseVersion *flag.Flag[string] // the release to deploy
98+
Environments *flag.Flag[[]string] // multiple for untenanted deployment
99+
Tenants *flag.Flag[[]string]
100+
TenantTags *flag.Flag[[]string]
101+
DeployAt *flag.Flag[string]
102+
MaxQueueTime *flag.Flag[string]
103+
Variables *flag.Flag[[]string]
104+
UpdateVariables *flag.Flag[bool]
105+
ExcludedSteps *flag.Flag[[]string]
106+
GuidedFailureMode *flag.Flag[string] // tri-state: true, false, or "use default". Can we model it with an optional bool?
107+
ForcePackageDownload *flag.Flag[bool]
108+
DeploymentTargets *flag.Flag[[]string]
109+
ExcludeTargets *flag.Flag[[]string]
110+
DeploymentFreezeNames *flag.Flag[[]string]
111+
DeploymentFreezeOverrideReason *flag.Flag[string]
107112
}
108113

109114
func NewDeployFlags() *DeployFlags {
110115
return &DeployFlags{
111-
Project: flag.New[string](FlagProject, false),
112-
ReleaseVersion: flag.New[string](FlagReleaseVersion, false),
113-
Environments: flag.New[[]string](FlagEnvironment, false),
114-
Tenants: flag.New[[]string](FlagTenant, false),
115-
TenantTags: flag.New[[]string](FlagTenantTag, false),
116-
MaxQueueTime: flag.New[string](FlagDeployAtExpiry, false),
117-
DeployAt: flag.New[string](FlagDeployAt, false),
118-
Variables: flag.New[[]string](FlagVariable, false),
119-
UpdateVariables: flag.New[bool](FlagUpdateVariables, false),
120-
ExcludedSteps: flag.New[[]string](FlagSkip, false),
121-
GuidedFailureMode: flag.New[string](FlagGuidedFailure, false),
122-
ForcePackageDownload: flag.New[bool](FlagForcePackageDownload, false),
123-
DeploymentTargets: flag.New[[]string](FlagDeploymentTarget, false),
124-
ExcludeTargets: flag.New[[]string](FlagExcludeDeploymentTarget, false),
116+
Project: flag.New[string](FlagProject, false),
117+
ReleaseVersion: flag.New[string](FlagReleaseVersion, false),
118+
Environments: flag.New[[]string](FlagEnvironment, false),
119+
Tenants: flag.New[[]string](FlagTenant, false),
120+
TenantTags: flag.New[[]string](FlagTenantTag, false),
121+
MaxQueueTime: flag.New[string](FlagDeployAtExpiry, false),
122+
DeployAt: flag.New[string](FlagDeployAt, false),
123+
Variables: flag.New[[]string](FlagVariable, false),
124+
UpdateVariables: flag.New[bool](FlagUpdateVariables, false),
125+
ExcludedSteps: flag.New[[]string](FlagSkip, false),
126+
GuidedFailureMode: flag.New[string](FlagGuidedFailure, false),
127+
ForcePackageDownload: flag.New[bool](FlagForcePackageDownload, false),
128+
DeploymentTargets: flag.New[[]string](FlagDeploymentTarget, false),
129+
ExcludeTargets: flag.New[[]string](FlagExcludeDeploymentTarget, false),
130+
DeploymentFreezeNames: flag.New[[]string](FlagDeploymentFreezeName, false),
131+
DeploymentFreezeOverrideReason: flag.New[string](FlagDeploymentFreezeOverrideReason, false),
125132
}
126133
}
127134

@@ -162,6 +169,8 @@ func NewCmdDeploy(f factory.Factory) *cobra.Command {
162169
flags.BoolVarP(&deployFlags.ForcePackageDownload.Value, deployFlags.ForcePackageDownload.Name, "", false, "Force re-download of packages")
163170
flags.StringArrayVarP(&deployFlags.DeploymentTargets.Value, deployFlags.DeploymentTargets.Name, "", nil, "Deploy to this target (can be specified multiple times)")
164171
flags.StringArrayVarP(&deployFlags.ExcludeTargets.Value, deployFlags.ExcludeTargets.Name, "", nil, "Deploy to targets except for this (can be specified multiple times)")
172+
flags.StringArrayVarP(&deployFlags.DeploymentFreezeNames.Value, deployFlags.DeploymentFreezeNames.Name, "", nil, "Override this deployment freeze (can be specified multiple times)")
173+
flags.StringVarP(&deployFlags.DeploymentFreezeOverrideReason.Value, deployFlags.DeploymentFreezeOverrideReason.Name, "", "", "Reason for overriding a deployment freeze")
165174

166175
flags.SortFlags = false
167176

@@ -202,20 +211,22 @@ func deployRun(cmd *cobra.Command, f factory.Factory, flags *DeployFlags) error
202211
}
203212

204213
options := &executor.TaskOptionsDeployRelease{
205-
ProjectName: flags.Project.Value,
206-
ReleaseVersion: flags.ReleaseVersion.Value,
207-
Environments: flags.Environments.Value,
208-
Tenants: flags.Tenants.Value,
209-
TenantTags: flags.TenantTags.Value,
210-
ScheduledStartTime: flags.DeployAt.Value,
211-
ScheduledExpiryTime: flags.MaxQueueTime.Value,
212-
ExcludedSteps: flags.ExcludedSteps.Value,
213-
GuidedFailureMode: flags.GuidedFailureMode.Value,
214-
ForcePackageDownload: flags.ForcePackageDownload.Value,
215-
DeploymentTargets: flags.DeploymentTargets.Value,
216-
ExcludeTargets: flags.ExcludeTargets.Value,
217-
Variables: parsedVariables,
218-
UpdateVariables: flags.UpdateVariables.Value,
214+
ProjectName: flags.Project.Value,
215+
ReleaseVersion: flags.ReleaseVersion.Value,
216+
Environments: flags.Environments.Value,
217+
Tenants: flags.Tenants.Value,
218+
TenantTags: flags.TenantTags.Value,
219+
ScheduledStartTime: flags.DeployAt.Value,
220+
ScheduledExpiryTime: flags.MaxQueueTime.Value,
221+
ExcludedSteps: flags.ExcludedSteps.Value,
222+
GuidedFailureMode: flags.GuidedFailureMode.Value,
223+
ForcePackageDownload: flags.ForcePackageDownload.Value,
224+
DeploymentTargets: flags.DeploymentTargets.Value,
225+
ExcludeTargets: flags.ExcludeTargets.Value,
226+
DeploymentFreezeNames: flags.DeploymentFreezeNames.Value,
227+
DeploymentFreezeOverrideReason: flags.DeploymentFreezeOverrideReason.Value,
228+
Variables: parsedVariables,
229+
UpdateVariables: flags.UpdateVariables.Value,
219230
}
220231

221232
// special case for FlagForcePackageDownload bool so we can tell if it was set on the cmdline or missing
@@ -250,6 +261,8 @@ func deployRun(cmd *cobra.Command, f factory.Factory, flags *DeployFlags) error
250261
resolvedFlags.GuidedFailureMode.Value = options.GuidedFailureMode
251262
resolvedFlags.DeploymentTargets.Value = options.DeploymentTargets
252263
resolvedFlags.ExcludeTargets.Value = options.ExcludeTargets
264+
resolvedFlags.DeploymentFreezeNames.Value = options.DeploymentFreezeNames
265+
resolvedFlags.DeploymentFreezeOverrideReason.Value = options.DeploymentFreezeOverrideReason
253266

254267
didMaskSensitiveVariable := false
255268
automationVariables := make(map[string]string, len(options.Variables))
@@ -281,6 +294,8 @@ func deployRun(cmd *cobra.Command, f factory.Factory, flags *DeployFlags) error
281294
resolvedFlags.DeploymentTargets,
282295
resolvedFlags.ExcludeTargets,
283296
resolvedFlags.Variables,
297+
resolvedFlags.DeploymentFreezeNames,
298+
resolvedFlags.DeploymentFreezeOverrideReason,
284299
)
285300
cmd.Printf("\nAutomation Command: %s\n", autoCmd)
286301

pkg/cmd/release/deploy/deploy_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,8 @@ func TestDeployCreate_AutomationMode(t *testing.T) {
14701470
"--update-variables",
14711471
"--target", "firstMachine", "--target", "secondMachine",
14721472
"--exclude-target", "thirdMachine",
1473+
"--deployment-freeze-name", "freeze 1", "--deployment-freeze-name", "freeze 2",
1474+
"--deployment-freeze-override-reason", "Testing",
14731475
"--variable", "Approver:John", "--variable", "Signoff:Jane",
14741476
"--output-format", "basic", // not neccessary, just means we don't need the follow up HTTP requests at the end to print the web link
14751477
})
@@ -1505,6 +1507,8 @@ func TestDeployCreate_AutomationMode(t *testing.T) {
15051507
"Approver": "John",
15061508
"Signoff": "Jane",
15071509
},
1510+
DeploymentFreezeNames: []string{"freeze 1", "freeze 2"},
1511+
DeploymentFreezeOverrideReason: "Testing",
15081512
},
15091513
}, requestBody)
15101514

@@ -1540,6 +1544,8 @@ func TestDeployCreate_AutomationMode(t *testing.T) {
15401544
"--update-variables",
15411545
"--target", "firstMachine", "--target", "secondMachine",
15421546
"--exclude-target", "thirdMachine",
1547+
"--deployment-freeze-name", "freeze 1",
1548+
"--deployment-freeze-override-reason", "Testing",
15431549
"--variable", "Approver:John", "--variable", "Signoff:Jane",
15441550
"--output-format", "basic", // not neccessary, just means we don't need the follow up HTTP requests at the end to print the web link
15451551
})
@@ -1576,6 +1582,8 @@ func TestDeployCreate_AutomationMode(t *testing.T) {
15761582
"Approver": "John",
15771583
"Signoff": "Jane",
15781584
},
1585+
DeploymentFreezeNames: []string{"freeze 1"},
1586+
DeploymentFreezeOverrideReason: "Testing",
15791587
},
15801588
}, requestBody)
15811589

pkg/executor/release.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,22 @@ func releaseCreate(octopus *client.Client, space *spaces.Space, input any) error
8686
// ----- Deploy Release --------------------------------------
8787

8888
type TaskOptionsDeployRelease struct {
89-
ProjectName string // required
90-
ReleaseVersion string // the release to deploy
91-
Environments []string // multiple for untenanted deployment, only one entry for tenanted deployment
92-
Tenants []string
93-
TenantTags []string
94-
ScheduledStartTime string
95-
ScheduledExpiryTime string
96-
ExcludedSteps []string
97-
GuidedFailureMode string // ["", "true", "false", "default"]. Note default and "" are the same, the only difference is whether interactive mode prompts you
98-
ForcePackageDownload bool
99-
DeploymentTargets []string
100-
ExcludeTargets []string
101-
Variables map[string]string
102-
UpdateVariables bool
89+
ProjectName string // required
90+
ReleaseVersion string // the release to deploy
91+
Environments []string // multiple for untenanted deployment, only one entry for tenanted deployment
92+
Tenants []string
93+
TenantTags []string
94+
ScheduledStartTime string
95+
ScheduledExpiryTime string
96+
ExcludedSteps []string
97+
GuidedFailureMode string // ["", "true", "false", "default"]. Note default and "" are the same, the only difference is whether interactive mode prompts you
98+
ForcePackageDownload bool
99+
DeploymentTargets []string
100+
ExcludeTargets []string
101+
Variables map[string]string
102+
UpdateVariables bool
103+
DeploymentFreezeNames []string
104+
DeploymentFreezeOverrideReason string
103105

104106
// extra behaviour commands
105107

@@ -140,15 +142,17 @@ func releaseDeploy(octopus *client.Client, space *spaces.Space, input any) error
140142

141143
// common properties
142144
abstractCmd := deployments.CreateExecutionAbstractCommandV1{
143-
SpaceID: space.ID,
144-
ProjectIDOrName: params.ProjectName,
145-
ForcePackageDownload: params.ForcePackageDownload,
146-
SpecificMachineNames: params.DeploymentTargets,
147-
ExcludedMachineNames: params.ExcludeTargets,
148-
SkipStepNames: params.ExcludedSteps,
149-
RunAt: params.ScheduledStartTime,
150-
NoRunAfter: params.ScheduledExpiryTime,
151-
Variables: params.Variables,
145+
SpaceID: space.ID,
146+
ProjectIDOrName: params.ProjectName,
147+
ForcePackageDownload: params.ForcePackageDownload,
148+
SpecificMachineNames: params.DeploymentTargets,
149+
ExcludedMachineNames: params.ExcludeTargets,
150+
SkipStepNames: params.ExcludedSteps,
151+
RunAt: params.ScheduledStartTime,
152+
NoRunAfter: params.ScheduledExpiryTime,
153+
Variables: params.Variables,
154+
DeploymentFreezeNames: params.DeploymentFreezeNames,
155+
DeploymentFreezeOverrideReason: params.DeploymentFreezeOverrideReason,
152156
}
153157

154158
b, err := strconv.ParseBool(params.GuidedFailureMode)

0 commit comments

Comments
 (0)