// createVersionItems populates and stores all the tasks and builds for a version according to // the given project config. func createVersionItems(v *version.Version, ref *model.ProjectRef, project *model.Project) error { for _, buildvariant := range project.BuildVariants { if buildvariant.Disabled { continue } buildId, err := model.CreateBuildFromVersion(project, v, buildvariant.Name, false, nil) if err != nil { return err } lastActivated, err := version.FindOne(version.ByLastVariantActivation(ref.Identifier, buildvariant.Name)) if err != nil { evergreen.Logger.Logf(slogger.ERROR, "Error getting activation time for bv %v", buildvariant.Name) return err } var lastActivation *time.Time if lastActivated != nil { for _, buildStatus := range lastActivated.BuildVariants { if buildStatus.BuildVariant == buildvariant.Name && buildStatus.Activated { lastActivation = &buildStatus.ActivateAt break } } } var activateAt time.Time var activated bool if lastActivation == nil { // if we don't have a last activation time then activate now. activateAt = time.Now() activated = true } else { activateAt = lastActivation.Add(time.Minute * time.Duration(ref.GetBatchTime(&buildvariant))) evergreen.Logger.Logf(slogger.INFO, "Going to activate bv %v for project %v, version %v at %v", buildvariant.Name, ref.Identifier, v.Id, activateAt) } v.BuildIds = append(v.BuildIds, buildId) v.BuildVariants = append(v.BuildVariants, version.BuildStatus{ BuildVariant: buildvariant.Name, Activated: activated, ActivateAt: activateAt, BuildId: buildId, }) } if err := v.Insert(); err != nil { evergreen.Logger.Errorf(slogger.ERROR, "Error inserting version %v: %v", v.Id, err) for _, buildStatus := range v.BuildVariants { if buildErr := model.DeleteBuild(buildStatus.BuildId); buildErr != nil { evergreen.Logger.Errorf(slogger.ERROR, "Error deleting build %v: %v", buildStatus.BuildId, buildErr) } } return err } return nil }
// Given the patch version and a list of build variants, creates new builds // with the patch's tasks. func AddNewBuildsForPatch(p *patch.Patch, patchVersion *version.Version, project *Project, buildVariants []string) (*version.Version, error) { // compute a list of the newly added build variants var newVariants []string for _, variant := range buildVariants { if !util.SliceContains(p.BuildVariants, variant) { newVariants = append(newVariants, variant) } } // update the patch if err := p.AddBuildVariants(buildVariants); err != nil { return nil, err } newBuildIds := make([]string, 0) newBuildStatuses := make([]version.BuildStatus, 0) tt := BuildTaskIdTable(project, patchVersion) for _, buildVariant := range newVariants { evergreen.Logger.Logf(slogger.INFO, "Creating build for version %v, buildVariant %v, activated = %v", patchVersion.Id, buildVariant, p.Activated) buildId, err := CreateBuildFromVersion( project, patchVersion, tt, buildVariant, p.Activated, p.Tasks) if err != nil { return nil, err } newBuildIds = append(newBuildIds, buildId) newBuildStatuses = append(newBuildStatuses, version.BuildStatus{ BuildVariant: buildVariant, BuildId: buildId, Activated: p.Activated, }, ) patchVersion.BuildIds = append(patchVersion.BuildIds, buildId) } err := version.UpdateOne( bson.M{version.IdKey: patchVersion.Id}, bson.M{ "$push": bson.M{ version.BuildIdsKey: bson.M{"$each": newBuildIds}, version.BuildVariantsKey: bson.M{"$each": newBuildStatuses}, }, }, ) if err != nil { return nil, err } return patchVersion, nil }