Ejemplo n.º 1
0
        private void SendEmail(int buildErrorLevel)
        {
            DatabaseInterface dbInterface = new DatabaseInterface();

            string toRecipients;

            string[]         tempRecipients = CollectionUtil.StringToStringArray(pbDataSet.GetBuildProperty("EmailRecipients"), new char[] { ',', ';' });
            StringCollection processedList  = new StringCollection();

            foreach (string recipient in tempRecipients)
            {
                if (recipient == null || recipient.Trim() == "")
                {
                    continue;
                }
                // don't add "@mobius.com" if "@" already specified
                else if (recipient.IndexOf("@") >= 0)
                {
                    processedList.Add(recipient.Trim());
                }
                else
                {
                    string validRecipient = dbInterface.GetUserEmail(recipient).Trim();
                    if (validRecipient.Length > 0)
                    {
                        processedList.Add(validRecipient.Trim() + "@asg.com");
                    }
                }
            }
            toRecipients = CollectionUtil.CollectionToString(processedList, ';');

            SmtpClient client = new SmtpClient("SMTPServerName");
            string     sender = dbInterface.GetUserEmail(Environment.UserName).Trim();

            sender = (sender.Length > 0) ? sender + "@asg.com" : Environment.UserName;
            MailMessage msg     = new MailMessage(new MailAddress(sender), new MailAddress(toRecipients));
            string      subject = "Build Report for " + pbDataSet.GetBuildProperty("ProductName") + " " +
                                  pbDataSet.GetBuildProperty("ProductVersion") + " " +
                                  pbDataSet.GetBuildProperty("ProductPlatform") + " ";
            string branchOrTrunkName = pbDataSet.GetBuildProperty("BranchOrTrunkName");

            if (branchOrTrunkName.ToUpper() != "DEVELOP")
            {
                subject += branchOrTrunkName + " ";
            }
            string releaseOrDebug = pbDataSet.GetBuildProperty("ReleaseOrDebug");

            if (releaseOrDebug != null)
            {
                if ((releaseOrDebug.ToUpper() == "RELEASE" && branchOrTrunkName.ToUpper() == "DEVELOP") ||
                    (releaseOrDebug.ToUpper() == "DEBUG" && branchOrTrunkName.ToUpper() != "DEVELOP"))
                {
                    subject += releaseOrDebug + " ";
                }
            }

            if (buildErrorLevel < 2)
            {
                subject += "(Build Succeeded)";
            }
            else
            {
                subject += "(Build Failed)";
            }

            // message body
            string        body;
            StringBuilder bodyText = new StringBuilder();

            bodyText.Append("\r\n");
            bodyText.Append("Build Machine:            " + Environment.MachineName + "\r\n");
            bodyText.Append("Build User:               "******"\\" + Environment.UserName + "\r\n");
            bodyText.Append("Build Start Time:         " + startTime + "\r\n");
            bodyText.Append("Build Completion Time:    " + completeTime + "\r\n");
            bodyText.Append("Build Status:             " + GetBuildErrorLevelString(buildErrorLevel) + "\r\n");
            bodyText.Append("Library Date:             " + pbDataSet.GetBuildProperty("LibraryDate") + "\r\n");
            bodyText.Append("-------------------------------------------------------------------------\r\n");

            if (isValidationSuccessful)
            {
                bodyText.Append("\r\nBuild Times:\r\n\r\n");
                string           buildTimesFilename = pbDataSet.GetBuildProperty("BuildTimesFileName");
                StringCollection buildTimes         = new StringCollection();
                if (File.Exists(buildTimesFilename))
                {
                    buildTimes = CollectionUtil.ReadValueFile(buildTimesFilename);
                }
                else
                {
                    buildTimes.Add("-- The Build Times Output File, " + buildTimesFilename + ", is Missing --");
                }
                foreach (string line in buildTimes)
                {
                    bodyText.Append(line + "\r\n");
                }
                bodyText.Append("-------------------------------------------------------------------------\r\n");

                bodyText.Append("\r\nBuild Step Results:\r\n\r\n");
                string           buildStepStatusFilename = pbDataSet.GetBuildProperty("BuildStepStatusFileName");
                StringCollection buildStepStatus         = new StringCollection();
                if (File.Exists(buildStepStatusFilename))
                {
                    buildStepStatus = CollectionUtil.ReadValueFile(pbDataSet.GetBuildProperty("BuildStepStatusFileName"));
                }
                else
                {
                    buildStepStatus.Add("-- The Build Step Status Output File, " + buildStepStatusFilename + ", is Missing --");
                }
                if (pbDataSet.GetBuildProperty("Populate") != null && pbDataSet.GetBuildProperty("Populate").ToLower() == "true")
                {
                    buildStepStatus = ChangeLogFilePaths(buildStepStatus, pbDataSet.GetBuildProperty("BuildPath"), pbDataSet.GetBuildProperty("PopulatePath"));
                }
                foreach (string line in buildStepStatus)
                {
                    bodyText.Append(line + "\r\n");
                }
                bodyText.Append("-------------------------------------------------------------------------\r\n");

                bodyText.Append("\r\nCheckBuild Results:\r\n\r\n");
                string           checkBuildResultsFilename = pbDataSet.GetBuildProperty("CheckBuildResultsFileName");
                StringCollection checkBuildResults         = new StringCollection();
                if (File.Exists(checkBuildResultsFilename))
                {
                    checkBuildResults = CollectionUtil.ReadValueFile(checkBuildResultsFilename);
                }
                else
                {
                    checkBuildResults.Add("-- The CheckBuild Output File, " + checkBuildResultsFilename + ", is Missing --");
                }
                foreach (string line in checkBuildResults)
                {
                    bodyText.Append(line + "\r\n");
                }
            }
            else
            {
                // unsuccessful validation
                bodyText.Append("\r\nLibraryBuilder was unable to create the local library on the build machine.");
                bodyText.Append("\r\nThe build could not start.");
                bodyText.Append("\r\nIf you get this error consistently, please contact VMS Administrator.");
                bodyText.Append("\r\n\r\nValidation output file: file://" + GetBuildLogfile());
                bodyText.Append("\r\n\r\n");
            }

            bodyText.Append("-------------------------------------------------------------------------\r\n");

            bodyText.Append("\r\nBuild Properties:\r\n\r\n");
            SortedList buildProperties = pbDataSet.GetBuildProperties();

            foreach (object key in buildProperties.Keys)
            {
                if (((string)key).ToUpper() != "UNIXPASSWORD")
                {
                    string keyString   = (string)key;
                    string valueString = buildProperties[key].ToString();
                    bodyText.Append(keyString + "=" + valueString + "\r\n");
                }
            }
            bodyText.Append("-------------------------------------------------------------------------\r\n");

            body = bodyText.ToString();
            // -- end message body

            MailMessage buildEmail = new MailMessage(new MailAddress(sender), new MailAddress(toRecipients));

            buildEmail.Subject = subject;
            buildEmail.Body    = body;

            client.Send(buildEmail);
        }
Ejemplo n.º 2
0
        private void SaveReport(int buildErrorLevel, NewMessage userMsg, bool isQuietMode)
        {
            string saveBuildReport = pbDataSet.GetBuildProperty("SaveBuildReport");

            if (saveBuildReport == null || saveBuildReport.ToUpper() != "TRUE")
            {
                return;
            }

            string buildName          = GetBuildName();
            string buildNameDirectory = Path.Combine(LBEnvironment.BuildReportRootDirectory, buildName);
            string buildDateDirectory = Path.Combine(buildNameDirectory, startTime.ToString("yyyyMMdd_HHmmss"));

            StringBuilder  buildReportStringBuilder = new StringBuilder();
            HtmlTextWriter reportWriter             = new HtmlTextWriter(new StringWriter(buildReportStringBuilder));

            reportWriter.WriteLine("<HTML><BODY><PRE>");

            reportWriter.WriteLine("Build Name:               " + buildName);
            reportWriter.WriteLine("Build Machine:            " + Environment.MachineName);
            reportWriter.WriteLine("Build User:               "******"\\" + Environment.UserName);
            reportWriter.WriteLine("Build Start Time:         " + startTime);
            reportWriter.WriteLine("Build Completion Time:    " + completeTime);
            reportWriter.WriteLine("Build Status:             " + GetBuildErrorLevelString(buildErrorLevel));
            reportWriter.WriteLine("Library Date:             " + pbDataSet.GetBuildProperty("LibraryDate"));
            reportWriter.WriteLine("-------------------------------------------------------------------------");
            reportWriter.WriteLine();

            if (isValidationSuccessful)
            {
                reportWriter.WriteLine("Build Times:");
                reportWriter.WriteLine();
                string           buildTimesFilename = pbDataSet.GetBuildProperty("BuildTimesFileName");
                StringCollection buildTimes         = new StringCollection();
                if (File.Exists(buildTimesFilename))
                {
                    buildTimes = CollectionUtil.ReadValueFile(buildTimesFilename);
                }
                else
                {
                    buildTimes.Add("-- The Build Times Output File, " + buildTimesFilename + ", is Missing --");
                }
                foreach (string line in buildTimes)
                {
                    reportWriter.WriteLine(line);
                }
                reportWriter.WriteLine("-------------------------------------------------------------------------");

                reportWriter.WriteLine();
                reportWriter.WriteLine("Build Step Results:");
                reportWriter.WriteLine();
                string           buildStepStatusFilename = pbDataSet.GetBuildProperty("BuildStepStatusFileName");
                StringCollection buildStepStatus         = new StringCollection();
                if (File.Exists(buildStepStatusFilename))
                {
                    buildStepStatus = CollectionUtil.ReadValueFile(buildStepStatusFilename);
                    buildStepStatus = ChangeToReportFormat(buildStepStatus, buildDateDirectory);
                }
                else
                {
                    buildStepStatus.Add("-- The Build Step Status Output File, " + buildStepStatusFilename + ", is Missing --");
                }
                foreach (string line in buildStepStatus)
                {
                    reportWriter.WriteLine(line);
                }
                reportWriter.WriteLine("-------------------------------------------------------------------------");

                reportWriter.WriteLine();
                reportWriter.WriteLine("CheckBuild Results:");
                reportWriter.WriteLine();
                string           checkBuildResultsFilename = pbDataSet.GetBuildProperty("CheckBuildResultsFileName");
                StringCollection checkBuildResults         = new StringCollection();
                if (File.Exists(checkBuildResultsFilename))
                {
                    checkBuildResults = CollectionUtil.ReadValueFile(checkBuildResultsFilename);
                }
                else
                {
                    checkBuildResults.Add("-- The CheckBuild Output File, " + checkBuildResultsFilename + ", is Missing --");
                }
                foreach (string line in checkBuildResults)
                {
                    reportWriter.WriteLine(line);
                }
                reportWriter.WriteLine("-------------------------------------------------------------------------");

                reportWriter.WriteLine();
                reportWriter.WriteLine("Build Properties:");
                reportWriter.WriteLine();
                SortedList buildProperties = pbDataSet.GetBuildProperties();
                foreach (object key in buildProperties.Keys)
                {
                    if (((string)key).ToUpper() != "UNIXPASSWORD")
                    {
                        string keyString   = (string)key;
                        string valueString = buildProperties[key].ToString();
                        reportWriter.WriteLine(keyString + "=" + valueString);
                    }
                }
            }
            else
            {
                // unsuccessful validation
                reportWriter.WriteLine("LibraryBuilder was unable to create the local library on the build machine.");
                reportWriter.WriteLine("The build could not start.");
                reportWriter.WriteLine("If you get this error consistently, please contact VMS Administrator.");
                reportWriter.WriteLine();

                string           msg  = "Validation output file: Error: file://" + GetBuildLogfile();
                StringCollection coll = new StringCollection();
                coll.Add(msg);
                coll = ChangeToReportFormat(coll, buildDateDirectory);
                if (coll.Count > 0)
                {
                    msg = coll[0];
                }

                reportWriter.WriteLine(msg);
                reportWriter.WriteLine();
            }

            reportWriter.WriteLine("-------------------------------------------------------------------------");

            reportWriter.WriteLine("</PRE></HTML></BODY>");
            reportWriter.Close();

            Directory.CreateDirectory(buildDateDirectory);
            string       buildReportFile = Path.Combine(buildDateDirectory, "BuildReport.htm");
            StreamWriter sw = File.CreateText(buildReportFile);

            sw.Write(buildReportStringBuilder.ToString());
            sw.Close();

            // copy logs
            // If validation failed, copy only the single log with LB's output.
            string copylogsScript = (isValidationSuccessful ? "CopyLogs.bat" : "CopyMainLog.bat");
            string buildPath      = pbDataSet.GetBuildProperty("BuildPath");

            RunBatch(Path.Combine(pbDataSet.GetBuildProperty("PBToolsPath"), copylogsScript),
                     buildPath + " \"" + buildDateDirectory + "\"",
                     buildPath, isQuietMode, (1 * 60 * 60 * 1000), userMsg);
        }
Ejemplo n.º 3
0
        private int PerformBuild(NewMessage userMsg, bool isQuietMode)
        {
            int buildErrorLevel = 0;

            string buildTimeEntry = DateTime.Now + " - Starting Build.";

            buildTimes.Add(buildTimeEntry);
            Console.WriteLine(buildTimeEntry);

            // make sure build_temp exists
            string buildTempDirectory = Path.Combine(pbDataSet.GetBuildProperty("BuildPath"), "build_temp");

            if (!Directory.Exists(buildTempDirectory))
            {
                Directory.CreateDirectory(buildTempDirectory);
            }

            // run the build batch file
            string buildCommandLineArgs = pbDataSet.GetBuildProperty("BuildDefinitionFileName");

            RunBatch(pbDataSet.GetBuildProperty("BuildBatchFileName"),
                     buildCommandLineArgs,
                     pbDataSet.GetBuildProperty("BuildPath"), isQuietMode,
                     (8 * 60 * 60 * 1000), userMsg);

            string buildCompleteTimeEntry = DateTime.Now + " - Build Finished.";

            Console.WriteLine(buildCompleteTimeEntry);

            // add entries into buildTimes from build
            string buildTimesFilename = pbDataSet.GetBuildProperty("BuildTimesFileName");

            if (File.Exists(buildTimesFilename))
            {
                StringCollection tempBuildTimes = CollectionUtil.ReadValueFile(pbDataSet.GetBuildProperty("BuildTimesFileName"));
                foreach (string line in tempBuildTimes)
                {
                    buildTimes.Add(line);
                }
            }
            buildTimes.Add(buildCompleteTimeEntry);

            // get success information
            bool warning  = false;
            bool error    = false;
            bool complete = false;

            char[] colon = new char[] { ':' };
            string status;

            string[] tokens;

            string           buildStepStatusFilename = pbDataSet.GetBuildProperty("BuildStepStatusFileName");
            StringCollection buildStepStatus         = new StringCollection();

            if (File.Exists(buildStepStatusFilename))
            {
                buildStepStatus = CollectionUtil.ReadValueFile(buildStepStatusFilename);
            }

            foreach (string line in buildStepStatus)
            {
                status = null;
                tokens = line.Split(colon);
                if (tokens.Length > 1)
                {
                    status = tokens[1].ToLower().Trim();
                }
                if (status == "error")
                {
                    error = true;
                }
                if (status == "warning")
                {
                    warning = true;
                }
                if (status == "complete")
                {
                    complete = true;
                }
            }
            if (!complete)
            {
                buildErrorLevel = 3;
            }
            else if (error)
            {
                buildErrorLevel = 2;
            }
            else if (warning)
            {
                buildErrorLevel = 1;
            }
            Console.WriteLine(GetBuildErrorLevelString(buildErrorLevel));

            return(buildErrorLevel);
        }