static CreateLabRunFromTemplateResponse JenkinsCreateLabRunFromTemplateRequest(CreateLabRunFromTemplateRequest req, TemplateProdService.LabRunInfo info) { var request = new CreateLabRunFromTemplateRequest() { TemplateId = req.TemplateId, LabRun = new TemplateProdService.LabRunInfo() { BranchName = info.BranchName, EnvironmentName = info.EnvironmentName, Purpose = info.Purpose, UserName = "******" } }; var client = new TemplateServiceClient(); var response = client.CreateLabRunFromTemplate(request); var labRunId = response.LabRunId; WriteHtmlCSSModel(labRunId); client.Close(); Console.WriteLine(); Console.WriteLine("Template link: http://tfx/LabrunManager/Templates.aspx?_templateId=" + req.TemplateId.ToString()); Console.WriteLine("Labrun link: http://tfx/LabrunManager/LabRunReport.aspx?labrunid=" + response.LabRunId.ToString()); FileStream fs = new FileStream(labRunId.ToString() + ".html", FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(@"<br> <div style=""width:100%; background-color:#3969AD""> <div style=""width:100%; font-size:20px; color: #FFFFFF"">Template and Labrun</div> </div> <br>" ); sw.WriteLine("\n" + "<table>\n" + " <tr>\n" + " <td>Template</td>\n" + " <td><a href=\"http://tfx/LabrunManager/Templates.aspx?_templateId=" + req.TemplateId.ToString() + "\">" + req.TemplateId.ToString() + "</a></td>\n" + " </tr>\n" + " <tr>\n" + " <td>Labrun</td>\n" + " <td><a href=\"http://tfx/LabrunManager/LabRunReport.aspx?labrunid=" + labRunId.ToString() + "\">" + labRunId.ToString() + "</a> </td>\n" + " </tr>\n" + "</table>\n"); sw.Flush(); sw.Close(); fs.Close(); return response; }
static void Run(int templateId, String environment, String purpose, int rerunTimes) { int Times = 0; var Request = new CreateLabRunFromTemplateRequest(); var LabrunInfo = new TemplateProdService.LabRunInfo(); Request.TemplateId = templateId; LabrunInfo.BranchName = "ExpWebTrunkCucumber"; LabrunInfo.EnvironmentName = environment; LabrunInfo.Purpose = purpose; var Response = JenkinsCreateLabRunFromTemplateRequest(Request, LabrunInfo); LabRunId = Response.LabRunId; JenkinsStartLabRun(LabRunId); GetLabRunStatusResponse status; while (true) { status = JenkinsGetLabRunStatus(LabRunId); if ((status.CompletePercent == 1.0) && (status.PassPercent != 1.0) && (Times < rerunTimes)) { //CreateRerunThread(); RerunFailedAssignments(LabRunId); Thread.Sleep(10000); if (Flag) { //RerunThread.Abort(); Console.WriteLine("Rerun Failed Assignments Time: " + (Times + 1).ToString()); Times++; Flag = false; } else Flag = false; } status = JenkinsGetLabRunStatus(LabRunId); if ((status.CompletePercent == 1.0) && (Times == rerunTimes) || (status.CompletePercent == 1.0) && (status.PassPercent == 1.0)) { FileStream fs = new FileStream(LabRunId.ToString() + ".html", FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(@"<br> <div style=""width:100%; background-color:#3969AD""> <div style=""width:100%; font-size:20px; color: #FFFFFF"">Status</div> </div> <br>"); sw.WriteLine("" + "<table>\n" + " <tr>\n" + " <td>Start Time</td>\n" + " <td><a>" + status.StartDate.ToString() + "</a></td>\n" + " </tr>\n" + " <tr>\n" + " <td>End Time</td>\n" + " <td>" + status.EndDate.ToString() + "</td>\n" + " </tr>\n" + " <tr>\n" + " <td>Total Tests</td>\n" + " <td><a>" + status.TotalTests.ToString() + "</a></td>\n" + " </tr>\n" + " <tr>\n" + " <td>Pass Count</td>\n" + " <td><a style= color:#00FF00>" + status.PassCount.ToString() + "</a></td>\n" + " </tr>\n" + " <tr>\n" + " <td>Pass Rate</td>\n" + " <td><a style= color:#00FF00>" + Math.Round(status.PassPercent * 100, 1).ToString() + "%" + "</a></td>\n" + " </tr>\n" + " <tr>\n" + " <td>Fail Count</td>\n" + " <td><a style= color:#FF0000>" + status.FailCount.ToString() + "</a></td>\n" + " </tr>\n" + " <tr>\n" + " <td>Fail Rate</td>\n" + " <td><a style= color:#FF0000>" + Math.Round(status.FailPercent * 100, 1).ToString() + "%" + "</a></td>\n" + " </tr>\n" + "</table>\n"); sw.Flush(); sw.Close(); fs.Close(); Console.WriteLine("Start Time: " + status.StartDate.ToString()); Console.WriteLine("End Time: " + status.EndDate.ToString()); Console.WriteLine("Total Tests: " + status.TotalTests.ToString()); Console.WriteLine("Pass Count: " + status.PassCount.ToString()); Console.WriteLine("Pass Rate: " + (status.PassPercent * 100).ToString() + "%"); Console.WriteLine("Fail Count: " + status.FailCount.ToString()); Console.WriteLine("Fail Rate: " + (status.FailPercent * 100).ToString() + "%"); Console.WriteLine(); // write pass or fail file if (status.PassPercent == 1.0) { FileStream fspof = new FileStream("Pass", FileMode.Create); StreamWriter swpof = new StreamWriter(fspof); swpof.Flush(); swpof.Close(); fspof.Close(); } else { FileStream fspof = new FileStream("Fail", FileMode.Create); StreamWriter swpof = new StreamWriter(fspof); swpof.Flush(); swpof.Close(); fspof.Close(); } break; } // not burn too much CPU Thread.Sleep(1000); } JenkinsGetLabRunDetails(LabRunId); }