本文整理匯總了Golang中github.com/evergreen-ci/evergreen/model/build.ById函數的典型用法代碼示例。如果您正苦於以下問題:Golang ById函數的具體用法?Golang ById怎麽用?Golang ById使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ById函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getBuildVariantHistory
// getBuildVariantHistory returns a slice of builds that surround a given build.
// As many as 'before' builds (less recent builds) plus as many as 'after' builds
// (more recent builds) are returned.
func getBuildVariantHistory(buildId string, before int, after int) ([]build.Build, error) {
b, err := build.FindOne(build.ById(buildId))
if err != nil {
return nil, err
}
if b == nil {
return nil, fmt.Errorf("no build with id %v", buildId)
}
lessRecentBuilds, err := build.Find(
build.ByBeforeRevision(b.Project, b.BuildVariant, b.RevisionOrderNumber).
WithFields(build.IdKey, build.TasksKey, build.StatusKey, build.VersionKey, build.ActivatedKey).
Limit(before))
if err != nil {
return nil, err
}
moreRecentBuilds, err := build.Find(
build.ByAfterRevision(b.Project, b.BuildVariant, b.RevisionOrderNumber).
WithFields(build.IdKey, build.TasksKey, build.StatusKey, build.VersionKey, build.ActivatedKey).
Limit(after))
if err != nil {
return nil, err
}
builds := make([]build.Build, 0, len(lessRecentBuilds)+len(moreRecentBuilds))
for i := len(moreRecentBuilds); i > 0; i-- {
builds = append(builds, moreRecentBuilds[i-1])
}
builds = append(builds, lessRecentBuilds...)
return builds, nil
}
示例2: TestBuildMarkStarted
func TestBuildMarkStarted(t *testing.T) {
Convey("With a build", t, func() {
testutil.HandleTestingErr(db.Clear(build.Collection), t, "Error clearing"+
" '%v' collection", build.Collection)
b := &build.Build{
Id: "build",
Status: evergreen.BuildCreated,
}
So(b.Insert(), ShouldBeNil)
Convey("marking it as started should update the status and"+
" start time, both in memory and in the database", func() {
startTime := time.Now()
So(build.TryMarkStarted(b.Id, startTime), ShouldBeNil)
// refresh from db and check again
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildStarted)
So(b.StartTime.Round(time.Second).Equal(
startTime.Round(time.Second)), ShouldBeTrue)
})
})
}
示例3: TestBuildMarkFinished
func TestBuildMarkFinished(t *testing.T) {
Convey("With a build", t, func() {
testutil.HandleTestingErr(db.Clear(build.Collection), t, "Error clearing"+
" '%v' collection", build.Collection)
startTime := time.Now()
b := &build.Build{
Id: "build",
StartTime: startTime,
}
So(b.Insert(), ShouldBeNil)
Convey("marking it as finished should update the status,"+
" finish time, and duration, both in memory and in the"+
" database", func() {
finishTime := time.Now()
So(b.MarkFinished(evergreen.BuildSucceeded, finishTime), ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildSucceeded)
So(b.FinishTime.Equal(finishTime), ShouldBeTrue)
So(b.TimeTaken, ShouldEqual, finishTime.Sub(startTime))
// refresh from db and check again
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildSucceeded)
So(b.FinishTime.Round(time.Second).Equal(
finishTime.Round(time.Second)), ShouldBeTrue)
So(b.TimeTaken, ShouldEqual, finishTime.Sub(startTime))
})
})
}
示例4: TestUpdateBuildStatusForTask
func TestUpdateBuildStatusForTask(t *testing.T) {
Convey("With two tasks and a build", t, func() {
testutil.HandleTestingErr(db.ClearCollections(task.Collection, build.Collection, version.Collection), t,
"Error clearing task and build collections")
displayName := "testName"
b := &build.Build{
Id: "buildtest",
Status: evergreen.BuildStarted,
Version: "abc",
}
v := &version.Version{
Id: b.Version,
Status: evergreen.VersionStarted,
}
testTask := task.Task{
Id: "testone",
DisplayName: displayName,
Activated: false,
BuildId: b.Id,
Project: "sample",
Status: evergreen.TaskFailed,
}
anotherTask := task.Task{
Id: "two",
DisplayName: displayName,
Activated: true,
BuildId: b.Id,
Project: "sample",
Status: evergreen.TaskFailed,
}
b.Tasks = []build.TaskCache{
{
Id: testTask.Id,
Status: evergreen.TaskSucceeded,
},
{
Id: anotherTask.Id,
Status: evergreen.TaskFailed,
},
}
So(b.Insert(), ShouldBeNil)
So(testTask.Insert(), ShouldBeNil)
So(anotherTask.Insert(), ShouldBeNil)
So(v.Insert(), ShouldBeNil)
Convey("updating the build for a task should update the build's status and the version's status", func() {
So(UpdateBuildAndVersionStatusForTask(testTask.Id), ShouldBeNil)
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildFailed)
v, err := version.FindOne(version.ById(v.Id))
So(v.Status, ShouldEqual, evergreen.VersionFailed)
})
})
}
示例5: getBuildVariantHistoryLastSuccess
// Given build id, get last successful build before this one
func getBuildVariantHistoryLastSuccess(buildId string) (*build.Build, error) {
b, err := build.FindOne(build.ById(buildId))
if err != nil {
return nil, err
}
if b.Status == evergreen.BuildSucceeded {
return b, nil
}
return b.PreviousSuccessful()
}
示例6: TestDeletingBuild
func TestDeletingBuild(t *testing.T) {
Convey("With a build", t, func() {
testutil.HandleTestingErr(db.Clear(build.Collection), t, "Error clearing"+
" '%v' collection", build.Collection)
b := &build.Build{
Id: "build",
}
So(b.Insert(), ShouldBeNil)
Convey("deleting it should remove it and all its associated"+
" tasks from the database", func() {
testutil.HandleTestingErr(db.ClearCollections(task.Collection), t, "Error"+
" clearing '%v' collection", task.Collection)
// insert two tasks that are part of the build, and one that isn't
matchingTaskOne := &task.Task{
Id: "matchingOne",
BuildId: b.Id,
}
So(matchingTaskOne.Insert(), ShouldBeNil)
matchingTaskTwo := &task.Task{
Id: "matchingTwo",
BuildId: b.Id,
}
So(matchingTaskTwo.Insert(), ShouldBeNil)
nonMatchingTask := &task.Task{
Id: "nonMatching",
BuildId: "blech",
}
So(nonMatchingTask.Insert(), ShouldBeNil)
// delete the build, make sure only it and its tasks are deleted
So(DeleteBuild(b.Id), ShouldBeNil)
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b, ShouldBeNil)
matchingTasks, err := task.Find(task.ByBuildId("build"))
So(err, ShouldBeNil)
So(len(matchingTasks), ShouldEqual, 0)
nonMatchingTask, err = task.FindOne(task.ById(nonMatchingTask.Id))
So(err, ShouldBeNil)
So(nonMatchingTask, ShouldNotBeNil)
})
})
}
示例7: TestMarkStart
func TestMarkStart(t *testing.T) {
Convey("With a task, build and version", t, func() {
testutil.HandleTestingErr(db.ClearCollections(task.Collection, build.Collection, version.Collection), t,
"Error clearing task and build collections")
displayName := "testName"
b := &build.Build{
Id: "buildtest",
Status: evergreen.BuildCreated,
Version: "abc",
}
v := &version.Version{
Id: b.Version,
Status: evergreen.VersionCreated,
}
testTask := task.Task{
Id: "testTask",
DisplayName: displayName,
Activated: true,
BuildId: b.Id,
Project: "sample",
Status: evergreen.TaskUndispatched,
Version: b.Version,
}
b.Tasks = []build.TaskCache{
{
Id: testTask.Id,
Status: evergreen.TaskUndispatched,
},
}
So(b.Insert(), ShouldBeNil)
So(testTask.Insert(), ShouldBeNil)
So(v.Insert(), ShouldBeNil)
Convey("when calling MarkStart, the task, version and build should be updated", func() {
So(MarkStart(testTask.Id), ShouldBeNil)
testTask, err := task.FindOne(task.ById(testTask.Id))
So(err, ShouldBeNil)
So(testTask.Status, ShouldEqual, evergreen.TaskStarted)
b, err := build.FindOne(build.ById(b.Id))
So(err, ShouldBeNil)
So(b.Status, ShouldEqual, evergreen.BuildStarted)
So(b.Tasks, ShouldNotBeNil)
So(len(b.Tasks), ShouldEqual, 1)
So(b.Tasks[0].Status, ShouldEqual, evergreen.TaskStarted)
v, err := version.FindOne(version.ById(v.Id))
So(err, ShouldBeNil)
So(v.Status, ShouldEqual, evergreen.VersionStarted)
})
})
}
示例8: getBuildInfo
// Returns a JSON response with the marshalled output of the build
// specified in the request.
func (restapi *restAPI) getBuildInfo(w http.ResponseWriter, r *http.Request) {
buildId := mux.Vars(r)["build_id"]
srcBuild, err := build.FindOne(build.ById(buildId))
if err != nil || srcBuild == nil {
msg := fmt.Sprintf("Error finding build '%v'", buildId)
statusCode := http.StatusNotFound
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
statusCode = http.StatusInternalServerError
}
restapi.WriteJSON(w, statusCode, responseError{Message: msg})
return
}
destBuild := &restBuild{}
// Copy the contents from the database into our local build type
err = angier.TransferByFieldNames(srcBuild, destBuild)
if err != nil {
msg := fmt.Sprintf("Error finding build '%v'", buildId)
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
restapi.WriteJSON(w, http.StatusInternalServerError, responseError{Message: msg})
return
}
destBuild.Tasks = make(buildStatusByTask, len(srcBuild.Tasks))
for _, task := range srcBuild.Tasks {
status := buildStatus{
Id: task.Id,
Status: task.Status,
TimeTaken: task.TimeTaken,
}
destBuild.Tasks[task.DisplayName] = status
}
restapi.WriteJSON(w, http.StatusOK, destBuild)
return
}
示例9: populateTaskBuildVersion
// populateTaskBuildVersion takes a task, build, and version ID and populates a projectContext
// with as many of the task, build, and version documents as possible.
// If any of the provided IDs is blank, they will be inferred from the more selective ones.
// Returns the project ID of the data found, which may be blank if the IDs are empty.
func (pc *projectContext) populateTaskBuildVersion(taskId, buildId, versionId string) (string, error) {
projectId := ""
var err error
// Fetch task if there's a task ID present; if we find one, populate build/version IDs from it
if len(taskId) > 0 {
pc.Task, err = task.FindOne(task.ById(taskId))
if err != nil {
return "", err
}
if pc.Task != nil {
// override build and version ID with the ones this task belongs to
buildId = pc.Task.BuildId
versionId = pc.Task.Version
projectId = pc.Task.Project
}
}
// Fetch build if there's a build ID present; if we find one, populate version ID from it
if len(buildId) > 0 {
pc.Build, err = build.FindOne(build.ById(buildId))
if err != nil {
return "", err
}
if pc.Build != nil {
versionId = pc.Build.Version
projectId = pc.Build.Project
}
}
if len(versionId) > 0 {
pc.Version, err = version.FindOne(version.ById(versionId))
if err != nil {
return "", err
}
if pc.Version != nil {
projectId = pc.Version.Identifier
}
}
return projectId, nil
}
示例10: activateElapsedBuilds
// Activates any builds if their BatchTimes have elapsed.
func (repoTracker *RepoTracker) activateElapsedBuilds(v *version.Version) (err error) {
projectId := repoTracker.ProjectRef.Identifier
hasActivated := false
now := time.Now()
for i, status := range v.BuildVariants {
// last comparison is to check that ActivateAt is actually set
if !status.Activated && now.After(status.ActivateAt) && !status.ActivateAt.IsZero() {
evergreen.Logger.Logf(slogger.INFO, "activating variant %v for project %v, revision %v",
status.BuildVariant, projectId, v.Revision)
// Go copies the slice value, we want to modify the actual value
status.Activated = true
status.ActivateAt = now
v.BuildVariants[i] = status
b, err := build.FindOne(build.ById(status.BuildId))
if err != nil {
evergreen.Logger.Logf(slogger.ERROR,
"error retrieving build for project %v, variant %v, build %v: %v",
projectId, status.BuildVariant, status.BuildId, err)
continue
}
evergreen.Logger.Logf(slogger.INFO, "activating build %v for project %v, variant %v",
status.BuildId, projectId, status.BuildVariant)
// Don't need to set the version in here since we do it ourselves in a single update
if err = model.SetBuildActivation(b.Id, true); err != nil {
evergreen.Logger.Logf(slogger.ERROR, "error activating build %v for project %v, variant %v: %v",
b.Id, projectId, status.BuildVariant, err)
continue
}
hasActivated = true
}
}
// If any variants were activated, update the stored version so that we don't
// attempt to activate them again
if hasActivated {
return v.UpdateBuildVariants()
}
return nil
}
示例11: getBuildStatus
// Returns a JSON response with the status of the specified build.
// The keys of the object are the task names.
func (restapi restAPI) getBuildStatus(w http.ResponseWriter, r *http.Request) {
buildId := mux.Vars(r)["build_id"]
b, err := build.FindOne(build.ById(buildId))
if err != nil || b == nil {
msg := fmt.Sprintf("Error finding build '%v'", buildId)
statusCode := http.StatusNotFound
if err != nil {
evergreen.Logger.Logf(slogger.ERROR, "%v: %v", msg, err)
statusCode = http.StatusInternalServerError
}
restapi.WriteJSON(w, statusCode, responseError{Message: msg})
return
}
result := buildStatusContent{
Id: buildId,
BuildVariant: b.BuildVariant,
Tasks: make(buildStatusByTask, len(b.Tasks)),
}
for _, task := range b.Tasks {
status := buildStatus{
Id: task.Id,
Status: task.Status,
TimeTaken: task.TimeTaken,
}
result.Tasks[task.DisplayName] = status
}
restapi.WriteJSON(w, http.StatusOK, result)
return
}
示例12: TestMarkAsDispatched
func TestMarkAsDispatched(t *testing.T) {
var (
taskId string
hostId string
buildId string
task *Task
myHost *host.Host
b *build.Build
)
Convey("With a task", t, func() {
taskId = "t1"
hostId = "h1"
buildId = "b1"
task = &Task{
Id: taskId,
BuildId: buildId,
}
myHost = &host.Host{
Id: hostId,
}
b = &build.Build{
Id: buildId,
Tasks: []build.TaskCache{
{Id: taskId},
},
}
testutil.HandleTestingErr(
db.ClearCollections(TasksCollection, build.Collection, host.Collection),
t, "Error clearing test collections")
So(task.Insert(), ShouldBeNil)
So(myHost.Insert(), ShouldBeNil)
So(b.Insert(), ShouldBeNil)
Convey("when marking the task as dispatched, the fields for"+
" the task, the host it is on, and the build it is a part of"+
" should be set to reflect this", func() {
// mark the task as dispatched
So(task.MarkAsDispatched(myHost, time.Now()), ShouldBeNil)
// make sure the task's fields were updated, both in memory and
// in the db
So(task.DispatchTime, ShouldNotResemble, time.Unix(0, 0))
So(task.Status, ShouldEqual, evergreen.TaskDispatched)
So(task.HostId, ShouldEqual, myHost.Id)
So(task.LastHeartbeat, ShouldResemble, task.DispatchTime)
task, err := FindTask(taskId)
So(err, ShouldBeNil)
So(task.DispatchTime, ShouldNotResemble, time.Unix(0, 0))
So(task.Status, ShouldEqual, evergreen.TaskDispatched)
So(task.HostId, ShouldEqual, myHost.Id)
So(task.LastHeartbeat, ShouldResemble, task.DispatchTime)
// make sure the build's fields were updated in the db
b, err = build.FindOne(build.ById(buildId))
So(err, ShouldBeNil)
So(b.Tasks[0].Status, ShouldEqual, evergreen.TaskDispatched)
})
})
}
示例13: modifyBuild
func (uis *UIServer) modifyBuild(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveProjectContext(r)
user := MustHaveUser(r)
if projCtx.Build == nil {
http.Error(w, "Not found", http.StatusNotFound)
return
}
reqBody, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer r.Body.Close()
putParams := struct {
Action string `json:"action"`
Active bool `json:"active"`
Abort bool `json:"abort"`
Priority string `json:"priority"`
TaskIds []string `json:"taskIds"`
}{}
err = json.Unmarshal(reqBody, &putParams)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// determine what action needs to be taken
switch putParams.Action {
case "abort":
if err := model.AbortBuild(projCtx.Build.Id, user.Id); err != nil {
http.Error(w, fmt.Sprintf("Error aborting build %v", projCtx.Build.Id), http.StatusInternalServerError)
return
}
model.RefreshTasksCache(projCtx.Build.Id)
case "set_priority":
priority, err := strconv.ParseInt(putParams.Priority, 10, 64)
if err != nil {
http.Error(w, "Bad priority value; must be int", http.StatusBadRequest)
return
}
if priority > evergreen.MaxTaskPriority {
if !uis.isSuperUser(user) {
http.Error(w, fmt.Sprintf("Insufficient access to set priority %v, can only set prior less than or equal to %v", priority, evergreen.MaxTaskPriority),
http.StatusBadRequest)
return
}
}
err = model.SetBuildPriority(projCtx.Build.Id, priority)
if err != nil {
http.Error(w, fmt.Sprintf("Error setting priority on build %v", projCtx.Build.Id),
http.StatusInternalServerError)
return
}
case "set_active":
err := model.SetBuildActivation(projCtx.Build.Id, putParams.Active, user.Id)
if err != nil {
http.Error(w, fmt.Sprintf("Error marking build %v as activated=%v", projCtx.Build.Id, putParams.Active),
http.StatusInternalServerError)
return
}
case "restart":
if err := model.RestartBuild(projCtx.Build.Id, putParams.TaskIds, putParams.Abort, user.Id); err != nil {
http.Error(w, fmt.Sprintf("Error restarting build %v", projCtx.Build.Id), http.StatusInternalServerError)
return
}
default:
uis.WriteJSON(w, http.StatusBadRequest, "Unrecognized action")
return
}
// After updating the build, fetch updated version to serve back to client
projCtx.Build, err = build.FindOne(build.ById(projCtx.Build.Id))
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
updatedBuild := uiBuild{
Build: *projCtx.Build,
CurrentTime: time.Now().UnixNano(),
Elapsed: time.Now().Sub(projCtx.Build.StartTime),
RepoOwner: projCtx.ProjectRef.Owner,
Repo: projCtx.ProjectRef.Repo,
Version: *projCtx.Version,
}
uiTasks, err := getUiTaskCache(projCtx.Build)
if err != nil {
uis.LoggedError(w, r, http.StatusInternalServerError, err)
return
}
updatedBuild.Tasks = uiTasks
uis.WriteJSON(w, http.StatusOK, updatedBuild)
}
示例14: loadAlertContext
// loadAlertContext fetches details from the database for all documents that are associated with the
// AlertRequest. For example, it populates the task/build/version/project using the
// task/build/version/project ids in the alert request document.
func (qp *QueueProcessor) loadAlertContext(a *alert.AlertRequest) (*AlertContext, error) {
aCtx := &AlertContext{AlertRequest: a}
aCtx.Settings = qp.config
taskId, projectId, buildId, versionId := a.TaskId, a.ProjectId, a.BuildId, a.VersionId
patchId := a.PatchId
var err error
if len(a.HostId) > 0 {
aCtx.Host, err = host.FindOne(host.ById(a.HostId))
if err != nil {
return nil, err
}
}
// Fetch task if there's a task ID present; if we find one, populate build/version IDs from it
if len(taskId) > 0 {
aCtx.Task, err = model.FindTask(taskId)
if err != nil {
return nil, err
}
if aCtx.Task != nil && aCtx.Task.Execution != a.Execution {
oldTaskId := fmt.Sprintf("%s_%v", taskId, a.Execution)
aCtx.Task, err = model.FindOneOldTask(bson.M{"_id": oldTaskId}, db.NoProjection, db.NoSort)
if err != nil {
return nil, err
}
}
if aCtx.Task != nil {
// override build and version ID with the ones this task belongs to
buildId = aCtx.Task.BuildId
versionId = aCtx.Task.Version
projectId = aCtx.Task.Project
aCtx.FailedTests = []model.TestResult{}
for _, test := range aCtx.Task.TestResults {
if test.Status == "fail" {
aCtx.FailedTests = append(aCtx.FailedTests, test)
}
}
}
}
// Fetch build if there's a build ID present; if we find one, populate version ID from it
if len(buildId) > 0 {
aCtx.Build, err = build.FindOne(build.ById(buildId))
if err != nil {
return nil, err
}
if aCtx.Build != nil {
versionId = aCtx.Build.Version
projectId = aCtx.Build.Project
}
}
if len(versionId) > 0 {
aCtx.Version, err = version.FindOne(version.ById(versionId))
if err != nil {
return nil, err
}
if aCtx.Version != nil {
projectId = aCtx.Version.Identifier
}
}
if len(patchId) > 0 {
if !patch.IsValidId(patchId) {
return nil, fmt.Errorf("patch id '%v' is not an object id", patchId)
}
aCtx.Patch, err = patch.FindOne(patch.ById(patch.NewId(patchId)).Project(patch.ExcludePatchDiff))
} else if aCtx.Version != nil {
// patch isn't in URL but the version in context has one, get it
aCtx.Patch, err = patch.FindOne(patch.ByVersion(aCtx.Version.Id).Project(patch.ExcludePatchDiff))
}
// If there's a finalized patch loaded into context but not a version, load the version
// associated with the patch as the context's version.
if aCtx.Version == nil && aCtx.Patch != nil && aCtx.Patch.Version != "" {
aCtx.Version, err = version.FindOne(version.ById(aCtx.Patch.Version).WithoutFields(version.ConfigKey))
if err != nil {
return nil, err
}
}
if len(projectId) > 0 {
aCtx.ProjectRef, err = qp.findProject(projectId)
if err != nil {
return nil, err
}
}
return aCtx, nil
}
示例15: UpdateBuildAndVersionStatusForTask
// UpdateBuildStatusForTask finds all the builds for a task and updates the
// status of the build based on the task's status.
func UpdateBuildAndVersionStatusForTask(taskId string) error {
// retrieve the task by the task id
t, err := task.FindOne(task.ById(taskId))
if err != nil {
return err
}
finishTime := time.Now()
// get all of the tasks in the same build
b, err := build.FindOne(build.ById(t.BuildId))
if err != nil {
return err
}
buildTasks, err := task.Find(task.ByBuildId(b.Id))
if err != nil {
return err
}
pushTaskExists := false
for _, t := range buildTasks {
if t.DisplayName == evergreen.PushStage {
pushTaskExists = true
}
}
failedTask := false
pushSuccess := true
pushCompleted := false
finishedTasks := 0
// update the build's status based on tasks for this build
for _, t := range buildTasks {
if task.IsFinished(t) {
finishedTasks += 1
// if it was a compile task, mark the build status accordingly
if t.DisplayName == evergreen.CompileStage {
if t.Status != evergreen.TaskSucceeded {
failedTask = true
finishedTasks = -1
err = b.MarkFinished(evergreen.BuildFailed, finishTime)
if err != nil {
evergreen.Logger.Errorf(slogger.ERROR, "Error marking build as finished: %v", err)
return err
}
break
}
} else if t.DisplayName == evergreen.PushStage {
pushCompleted = true
// if it's a finished push, check if it was successful
if t.Status != evergreen.TaskSucceeded {
err = b.UpdateStatus(evergreen.BuildFailed)
if err != nil {
evergreen.Logger.Errorf(slogger.ERROR, "Error updating build status: %v", err)
return err
}
pushSuccess = false
}
} else {
// update the build's status when a test task isn't successful
if t.Status != evergreen.TaskSucceeded {
err = b.UpdateStatus(evergreen.BuildFailed)
if err != nil {
evergreen.Logger.Errorf(slogger.ERROR, "Error updating build status: %v", err)
return err
}
failedTask = true
}
}
}
}
// if there are no failed tasks, mark the build as started
if !failedTask {
err = b.UpdateStatus(evergreen.BuildStarted)
if err != nil {
evergreen.Logger.Errorf(slogger.ERROR, "Error updating build status: %v", err)
return err
}
}
// if a compile task didn't fail, then the
// build is only finished when both the compile
// and test tasks are completed or when those are
// both completed in addition to a push (a push
// does not occur if there's a failed task)
if finishedTasks >= len(buildTasks)-1 {
if !failedTask {
if pushTaskExists { // this build has a push task associated with it.
if pushCompleted && pushSuccess { // the push succeeded, so mark the build as succeeded.
err = b.MarkFinished(evergreen.BuildSucceeded, finishTime)
if err != nil {
evergreen.Logger.Errorf(slogger.ERROR, "Error marking build as finished: %v", err)
return err
}
} else if pushCompleted && !pushSuccess { // the push failed, mark build failed.
err = b.MarkFinished(evergreen.BuildFailed, finishTime)
if err != nil {
evergreen.Logger.Errorf(slogger.ERROR, "Error marking build as finished: %v", err)
//.........這裏部分代碼省略.........