static bool TryRunAfterCheckinPlan( RestApi restApi, Branch branch, MergeReport mergeReport, string taskNumber, int csetId, string labelName, TrunkBotConfiguration botConfig) { string repSpec = string.Format("{0}@{1}", branch.Repository, botConfig.Server); string scmSpecToSwitchTo = string.Format("cs:{0}@{1}", csetId, repSpec); string comment = string.Format( "Running plan after merging branch {0}", branch.FullName); BuildProperties properties = CreateBuildProperties( restApi, taskNumber, branch.FullName, labelName, BuildProperties.StageValues.POST_CHECKIN, botConfig); int iniTime = Environment.TickCount; TrunkMergebotApi.CI.PlanResult buildResult = TrunkMergebotApi.CI.Build( restApi, botConfig.CI.Plug, botConfig.CI.PlanAfterCheckin, scmSpecToSwitchTo, comment, properties); BuildMergeReport.AddBuildTimeProperty(mergeReport, Environment.TickCount - iniTime); string message = string.Empty; //TODO:shall we set any attr in trunk branch? if (buildResult.Succeeded) { BuildMergeReport.AddSucceededBuildProperty( mergeReport, botConfig.CI.PlanAfterCheckin); message = string.Format( "Plan execution after merging branch {0} was successful.", branch.FullName); Notifier.NotifyTaskStatus( restApi, branch.Owner, message, botConfig.Notifications); return(true); } BuildMergeReport.AddFailedBuildProperty( mergeReport, botConfig.CI.PlanAfterCheckin, buildResult.Explanation); message = string.Format( "Plan execution failed after merging branch {0}.\nReason: {1}", branch.FullName, buildResult.Explanation); Notifier.NotifyTaskStatus( restApi, branch.Owner, message, botConfig.Notifications); return(false); }
static bool TryBuildTask( RestApi restApi, Branch branch, MergeReport mergeReport, string taskNumber, int shelveId, TrunkBotConfiguration botConfig, string codeReviewsStorageFile) { if (botConfig.CI == null) { string message = "No CI plug was set for this mergebot. Therefore, no " + "build actions for task " + taskNumber + " will be performed."; mLog.Info(message); Notifier.NotifyTaskStatus( restApi, branch.Owner, message, botConfig.Notifications); return(true); } ChangeTaskStatus.SetTaskAsTesting(restApi, branch, taskNumber, string.Format( "Starting to test branch {0}.", branch.FullName), botConfig); string repSpec = string.Format("{0}@{1}", branch.Repository, botConfig.Server); string scmSpecToSwitchTo = string.Format("sh:{0}@{1}", shelveId, repSpec); string comment = string.Format( "Building branch {0}", branch.FullName); BuildProperties properties = CreateBuildProperties( restApi, taskNumber, branch.FullName, string.Empty, BuildProperties.StageValues.PRE_CHECKIN, botConfig); int iniTime = Environment.TickCount; TrunkMergebotApi.CI.PlanResult buildResult = TrunkMergebotApi.CI.Build( restApi, botConfig.CI.Plug, botConfig.CI.PlanBranch, scmSpecToSwitchTo, comment, properties); BuildMergeReport.AddBuildTimeProperty(mergeReport, Environment.TickCount - iniTime); if (buildResult.Succeeded) { BuildMergeReport.AddSucceededBuildProperty(mergeReport, botConfig.CI.PlanBranch); return(true); } BuildMergeReport.AddFailedBuildProperty(mergeReport, botConfig.CI.PlanBranch, buildResult.Explanation); ChangeTaskStatus.SetTaskAsFailed( restApi, branch, taskNumber, string.Format( "Branch {0} build failed. \nReason: {1}", branch.FullName, buildResult.Explanation), botConfig, codeReviewsStorageFile); return(false); }