| 124 | } |
| 125 | |
| 126 | func gitRunbookRun(octopus *client.Client, space *spaces.Space, input any) error { |
| 127 | params, ok := input.(*TaskOptionsGitRunbookRun) |
| 128 | if !ok { |
| 129 | return errors.New("invalid input type; expecting TaskOptionsGitRunbookRun") |
| 130 | } |
| 131 | if space == nil { |
| 132 | return errors.New("space must be specified") |
| 133 | } |
| 134 | |
| 135 | // we have the provided project name; go look it up |
| 136 | if params.ProjectName == "" { |
| 137 | return errors.New("project must be specified") |
| 138 | } |
| 139 | if params.RunbookName == "" { |
| 140 | return errors.New("runbook name must be specified") |
| 141 | } |
| 142 | if len(params.Environments) == 0 { |
| 143 | return errors.New("environment(s) must be specified") |
| 144 | } |
| 145 | |
| 146 | if params.GitReference == "" { |
| 147 | return errors.New("git reference must be specified") |
| 148 | } |
| 149 | |
| 150 | // common properties |
| 151 | abstractCmd := deployments.CreateExecutionAbstractCommandV1{ |
| 152 | SpaceID: space.ID, |
| 153 | ProjectIDOrName: params.ProjectName, |
| 154 | ForcePackageDownload: params.ForcePackageDownload, |
| 155 | SpecificMachineNames: params.RunTargets, |
| 156 | ExcludedMachineNames: params.ExcludeTargets, |
| 157 | SkipStepNames: params.ExcludedSteps, |
| 158 | RunAt: params.ScheduledStartTime, |
| 159 | NoRunAfter: params.ScheduledExpiryTime, |
| 160 | Variables: params.Variables, |
| 161 | } |
| 162 | |
| 163 | b, err := strconv.ParseBool(params.GuidedFailureMode) |
| 164 | if err == nil { |
| 165 | abstractCmd.UseGuidedFailure = &b |
| 166 | } else { |
| 167 | // else they must have specified nothing, or perhaps "default". Sanity check it's not garbage |
| 168 | if params.GuidedFailureMode != "" && !strings.EqualFold("default", params.GuidedFailureMode) { |
| 169 | return fmt.Errorf("'%s' is not a valid value for guided failure mode", params.GuidedFailureMode) |
| 170 | } |
| 171 | } |
| 172 | runCommand := runbooks.NewGitRunbookRunCommandV1(space.ID, params.ProjectName) |
| 173 | runCommand.RunbookName = params.RunbookName |
| 174 | runCommand.EnvironmentNames = params.Environments |
| 175 | runCommand.Tenants = params.Tenants |
| 176 | runCommand.TenantTags = params.TenantTags |
| 177 | runCommand.GitRef = params.GitReference |
| 178 | |
| 179 | runCommand.PackageVersion = params.DefaultPackageVersion |
| 180 | |
| 181 | if len(params.PackageVersionOverrides) > 0 { |
| 182 | runCommand.Packages = params.PackageVersionOverrides |
| 183 | } |