func BuildPublish(buildName, buildNumber string, flags *utils.BuildInfoFlags) error { err := utils.PreCommandSetup(flags) if err != nil { return err } buildData, err := utils.ReadBuildInfoFiles(buildName, buildNumber) if err != nil { return err } if len(buildData) == 0 { return cliutils.CheckError(fmt.Errorf("Can't find any files related to build name: %q, number: %q", buildName, buildNumber)) } sort.Sort(buildData) buildInfo := createNewBuildInfo() buildInfo.Name = buildName buildInfo.Number = buildNumber buildGeneralDetails, err := utils.ReadBuildInfoGeneralDetails(buildName, buildNumber) if err != nil { return err } buildInfo.Started = buildGeneralDetails.Timestamp.Format("2006-01-02T15:04:05.000-0700") artifactsSet, dependenciesSet, env, err := prepareBuildInfoData(buildData, createIncludeFilter(flags), createExcludeFilter(flags)) if err != nil { return err } if len(env) != 0 { buildInfo.Propertires = env } module := createModule(buildName, artifactsSet, dependenciesSet) buildInfo.Modules = append(buildInfo.Modules, module) marshaledBuildInfo, err := json.Marshal(buildInfo) if cliutils.CheckError(err) != nil { return err } if flags.IsDryRun() { fmt.Println(cliutils.IndentJson(marshaledBuildInfo)) return nil } httpClientsDetails := utils.GetArtifactoryHttpClientDetails(flags.ArtDetails) utils.SetContentType("application/vnd.org.jfrog.artifactory+json", &httpClientsDetails.Headers) log.Info("Deploying build info...") resp, body, err := utils.PublishBuildInfo(flags.ArtDetails.Url, marshaledBuildInfo, httpClientsDetails) if err != nil { return err } if resp.StatusCode != 204 { return cliutils.CheckError(errors.New("Artifactory response: " + resp.Status + "\n" + cliutils.IndentJson(body))) } log.Debug("Artifactory response:", resp.Status) log.Info("Build info successfully deployed. Browse it in Artifactory under " + flags.ArtDetails.Url + "webapp/builds/" + buildName + "/" + buildNumber) if err = utils.RemoveBuildDir(buildName, buildNumber); err != nil { return err } return nil }
func addBuildProps(uploadFiles *utils.Files, flags *UploadFlags) (err error) { if flags.BuildName == "" || flags.BuildNumber == "" { return } props := uploadFiles.Props if props != "" { props += ";" } props += "build.name=" + flags.BuildName props += ";build.number=" + flags.BuildNumber buildGeneralDetails, err := utils.ReadBuildInfoGeneralDetails(flags.BuildName, flags.BuildNumber) if err != nil { return } props += ";build.timestamp=" + strconv.FormatInt(buildGeneralDetails.Timestamp.UnixNano()/int64(time.Millisecond), 10) uploadFiles.Props = props return }