| 54 | } |
| 55 | |
| 56 | func runbookRun(octopus *client.Client, space *spaces.Space, input any) error { |
| 57 | params, ok := input.(*TaskOptionsRunbookRun) |
| 58 | if !ok { |
| 59 | return errors.New("invalid input type; expecting TaskOptionsRunbookRun") |
| 60 | } |
| 61 | if space == nil { |
| 62 | return errors.New("space must be specified") |
| 63 | } |
| 64 | |
| 65 | // we have the provided project name; go look it up |
| 66 | if params.ProjectName == "" { |
| 67 | return errors.New("project must be specified") |
| 68 | } |
| 69 | if params.RunbookName == "" { |
| 70 | return errors.New("runbook name must be specified") |
| 71 | } |
| 72 | if len(params.Environments) == 0 { |
| 73 | return errors.New("environment(s) must be specified") |
| 74 | } |
| 75 | |
| 76 | // common properties |
| 77 | abstractCmd := deployments.CreateExecutionAbstractCommandV1{ |
| 78 | SpaceID: space.ID, |
| 79 | ProjectIDOrName: params.ProjectName, |
| 80 | ForcePackageDownload: params.ForcePackageDownload, |
| 81 | SpecificMachineNames: params.RunTargets, |
| 82 | ExcludedMachineNames: params.ExcludeTargets, |
| 83 | SkipStepNames: params.ExcludedSteps, |
| 84 | RunAt: params.ScheduledStartTime, |
| 85 | NoRunAfter: params.ScheduledExpiryTime, |
| 86 | Variables: params.Variables, |
| 87 | } |
| 88 | |
| 89 | b, err := strconv.ParseBool(params.GuidedFailureMode) |
| 90 | if err == nil { |
| 91 | abstractCmd.UseGuidedFailure = &b |
| 92 | } else { |
| 93 | // else they must have specified nothing, or perhaps "default". Sanity check it's not garbage |
| 94 | if params.GuidedFailureMode != "" && !strings.EqualFold("default", params.GuidedFailureMode) { |
| 95 | return fmt.Errorf("'%s' is not a valid value for guided failure mode", params.GuidedFailureMode) |
| 96 | } |
| 97 | } |
| 98 | runCommand := runbooks.NewRunbookRunCommandV1(space.ID, params.ProjectName) |
| 99 | runCommand.RunbookName = params.RunbookName |
| 100 | runCommand.EnvironmentNames = params.Environments |
| 101 | runCommand.Tenants = params.Tenants |
| 102 | runCommand.TenantTags = params.TenantTags |
| 103 | runCommand.Snapshot = params.Snapshot |
| 104 | |
| 105 | runCommand.CreateExecutionAbstractCommandV1 = abstractCmd |
| 106 | |
| 107 | runResponse, err := runbooks.RunbookRunV1(octopus, runCommand) |
| 108 | if err != nil { |
| 109 | return err |
| 110 | } |
| 111 | params.Response = runResponse |
| 112 | return nil |
| 113 | } |