Пример #1
0
        public static bool TryGetNewBuildFromTFS(List <BuildInfo> tfsBuilds)
        {
            bool result  = false;
            var  details = TFSHelper.GetSuccessfulBuildDetails();

            foreach (var detail in details)
            {
                var isIncluded = tfsBuilds.Where(t => t.TFSBuildNumber.Equals(detail.BuildNumber)).Count();
                if (isIncluded == 0)
                {
                    Console.WriteLine("Found: {0}", detail.BuildNumber);
                    lock (tfsBuilds)
                    {
                        tfsBuilds.Add(new BuildInfo()
                        {
                            TFSBuildNumber    = detail.BuildNumber,
                            DropFolder        = detail.DropLocation,
                            BuildStatus       = detail.Status.ToString(),
                            BuildFinishedTime = detail.FinishTime,
                            TestStatus        = TestStatus.NotStart,
                        });
                    }
                    result = true;
                }
            }
            return(result);
        }
Пример #2
0
        static void Main(string[] args)
        {
            // TFSHelper.RefreshTFSBuildsConfig();
            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
            if (args.Length == 0)
            {
                TFSHelper.LoadTFSBuildFromFile(TFSBUILDFILE, out tfsBuilds);
                TFSMonitorWorker tfsMonitor = new TFSMonitorWorker(tfsBuilds);
                tfsMonitor.Start();
                TestWorker testWorker = new TestWorker(tfsBuilds);
                testWorker.Start();
            }
            else
            {
                string dropFolder = args[0];
                string tag;
                Console.WriteLine("Test triggered for {0}", dropFolder);
                Console.WriteLine("Start Time: {0}", DateTimeOffset.Now);
                if (!TestHelper.BuildDockerImage(dropFolder, out tag))
                {
                    return;
                }
                Console.WriteLine("Image tag is {0}", tag);

                AzureFileHelper.UploadPaasDBUpgradeFileToAzureFile(tag, dropFolder + "\\retail\\amd64\\");

                var taskIds = TestHelper.StartTests(tag);

                taskIds.ForEach(i => Console.WriteLine("Start Testing: {0}", i));

                var stop = false;
                while (!stop)
                {
                    stop = true;
                    foreach (Guid taskId in taskIds)
                    {
                        bool result;
                        if (result = TestHelper.CheckFinished(taskId))
                        {
                            Console.WriteLine("Test task {0} completed", taskId);
                        }
                        stop = stop && result;
                    }
                    Thread.Sleep(TEST_MONITOR_INTERVAL);
                }
                Console.WriteLine("Completed!!!");
            }
        }
Пример #3
0
 protected override void DoWork(CancellationToken cancel)
 {
     while (!cancel.IsCancellationRequested)
     {
         Console.WriteLine("Fetching new builds from TFS");
         if (TFSHelper.TryGetNewBuildFromTFS(tfsBuilds))
         {
             Console.WriteLine("Found new builds");
             TFSHelper.WriteTFSBuildToFile(TFSBUILDFILE, tfsBuilds);
         }
         else
         {
             Console.WriteLine("No new builds");
         }
         Thread.Sleep(TFS_MONITOR_INTERVAL);
     }
 }
Пример #4
0
        protected override void DoWork(CancellationToken cancel)
        {
            while (!cancel.IsCancellationRequested)
            {
                try
                {
                    var build = FindNextTestNotFinished();
                    if (build == null)
                    {
                        Thread.Sleep(TEST_WAIT_INTERVAL);
                    }
                    else if (build.TestStatus == TestStatus.NotStart)
                    {
                        build.TestStatus = TestStatus.TestPrepare;
                        TFSHelper.WriteTFSBuildToFile(TFSBUILDFILE, tfsBuilds);
                        Console.WriteLine("Prepare test for {0}", build.TFSBuildNumber);
                    }
                    else if (build.TestStatus == TestStatus.TestPrepare)
                    {
                        string tag = build.ImageTag;
                        if (tag == null)
                        {
                            if (!TestHelper.BuildDockerImage(build.DropFolder, out tag))
                            {
                                build.TestStatus = TestStatus.Finished;
                                TFSHelper.WriteTFSBuildToFile(TFSBUILDFILE, tfsBuilds);
                                continue;
                            }
                            build.ImageTag = tag;
                            TFSHelper.WriteTFSBuildToFile(TFSBUILDFILE, tfsBuilds);
                        }
                        Console.WriteLine("Image tag for {0} is {1}", build.TFSBuildNumber, build.ImageTag);

                        build.TestStartTime = DateTimeOffset.Now;
                        build.TestTaskId    = TestHelper.StartTest(0, tag);
                        build.TestStatus    = TestStatus.Testing;
                        TFSHelper.WriteTFSBuildToFile(TFSBUILDFILE, tfsBuilds);
                        Console.WriteLine("Start testing {0} taskId = {1}", build.TFSBuildNumber, build.TestTaskId);
                    }
                    else if (build.TestStatus == TestStatus.Testing)
                    {
                        if (TestHelper.CheckFinished(build.TestTaskId))
                        {
                            build.TestFinishedTime = DateTimeOffset.Now;
                            build.TestStatus       = TestStatus.Finished;
                            TFSHelper.WriteTFSBuildToFile(TFSBUILDFILE, tfsBuilds);
                            Console.WriteLine("{0} finished", build.TFSBuildNumber);
                        }
                        else
                        {
                            Thread.Sleep(TEST_MONITOR_INTERVAL);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Thread.Sleep(TEST_WAIT_INTERVAL);
                }
            }
        }