(opts *UploadOptions)
| 99 | } |
| 100 | |
| 101 | func uploadRun(opts *UploadOptions) error { |
| 102 | if !opts.NoPrompt { |
| 103 | // Prompt for missing arguments |
| 104 | err := PromptMissing(opts) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | overwriteMode := opts.OverwriteMode.Value |
| 111 | resolvedOverwriteMode := buildinformation.OverwriteMode("") |
| 112 | switch strings.ToLower(overwriteMode) { |
| 113 | case "fail", "failifexists", "": // include aliases from old CLI, default (empty string) = fail |
| 114 | resolvedOverwriteMode = buildinformation.OverwriteModeFailIfExists |
| 115 | case "ignore", "ignoreifexists": |
| 116 | resolvedOverwriteMode = buildinformation.OverwriteModeIgnoreIfExists |
| 117 | case "overwrite", "overwriteexisting", "replace": |
| 118 | resolvedOverwriteMode = buildinformation.OverwriteModeOverwriteExisting |
| 119 | default: |
| 120 | return fmt.Errorf("invalid value '%s' for --overwrite-mode. Valid values are 'fail', 'ignore', 'overwrite'", overwriteMode) |
| 121 | } |
| 122 | |
| 123 | var buildInformation buildinformation.OctopusBuildInformation |
| 124 | if opts.File.Value != "" { |
| 125 | jsonFile, err := os.ReadFile(opts.File.Value) |
| 126 | if err != nil { |
| 127 | return err |
| 128 | } |
| 129 | |
| 130 | err = json.Unmarshal(jsonFile, &buildInformation) |
| 131 | if err != nil { |
| 132 | return err |
| 133 | } |
| 134 | |
| 135 | fmt.Printf("Build information:\n%s\n", output.Dim(string(jsonFile))) |
| 136 | } |
| 137 | |
| 138 | if len(buildInformation.Commits) >= 200 { |
| 139 | fmt.Printf("%s\n", output.Yellow("Warning: Build information contains 200 or more commits, this may be due to a misconfiguration of your build server.")) |
| 140 | } |
| 141 | |
| 142 | for _, pkgIdString := range opts.PackageId.Value { |
| 143 | cmd := buildinformation.NewCreateBuildInformationCommand(opts.Space.GetID(), pkgIdString, opts.Version.Value, buildInformation) |
| 144 | cmd.OverwriteMode = resolvedOverwriteMode |
| 145 | |
| 146 | uploadedBuildInfo, err := buildinformation.Add(opts.Client, cmd) |
| 147 | if err != nil { |
| 148 | return err |
| 149 | } |
| 150 | |
| 151 | _, err = fmt.Fprintf(opts.Out, "\nSuccessfully uploaded build information for '%s' version '%s' (%s).\n", uploadedBuildInfo.PackageID, uploadedBuildInfo.Version, uploadedBuildInfo.ID) |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | link := output.Bluef("%s/app#/%s/library/buildinformation/%s", opts.Host, opts.Space.GetID(), uploadedBuildInfo.GetID()) |
| 157 | fmt.Fprintf(opts.Out, "View this build information on Octopus Deploy: %s\n", link) |
| 158 | } |
no test coverage detected