コード例 #1
0
ファイル: Program.cs プロジェクト: krupineg/Tobii.Build.Robot
        static void Main(string[] args)
        {
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                Console.WriteLine((e.ExceptionObject as Exception).Message);
            };
            var teamcityConfig = new Rest.TeamCity.ConfigurationProvider();
            var restClient     = new RestClient(
                teamcityConfig.Host,
                teamcityConfig.Login,
                teamcityConfig.Password,
                MediaType.Json);
            var tc               = new TeamCityApi(restClient);
            var gateway          = new Gateway(new[] { tc });
            var presenterFactory = new PresenterFactory();
            var output           = new Output(
                presenterFactory,
                new IOutputStream[] {
                new ConsoleStream(),
                new FileStream("log.txt")
            });
            var cancellationSource = new CancellationTokenSource();

            output.Write("build bot greetings you");
            output.Write("type exit to leave bot");

            var client   = new TelegramBotClient(new ConfigurationProvider().ApiKey);
            var commands = new List <CommandBase>
            {
                new StartCommand(cancellationSource),
                new ExitCommand(cancellationSource),
                new TeamcityGetBuildQueueCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetProjectsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetProjectCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBranchesCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildTypesCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetAgentsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityEnqueueBuild(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetRunningBuildsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityEnqueueAgentCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBranchCommand(gateway.For <ITeamCity>(), cancellationSource)
            };
            var help = new HelpCommand(commands, cancellationSource);

            commands.Add(help);
            var commandsExecutor = new CommandsExecutor(commands);
            var inputStream      = new InputPipeline();
            var consoleListener  = new ConsoleCommandProducer(inputStream);
            var runLooper        = new RunLooper(inputStream, commandsExecutor, consoleListener, output, cancellationSource);
            var store            = new MemoryStore();

            using (var botWrapper = new BotWrapper(client, inputStream, presenterFactory, cancellationSource, commandsExecutor, output, store))
            {
                botWrapper.Start();
                runLooper.Run();
            }
        }
コード例 #2
0
ファイル: Driver.cs プロジェクト: olegshegula/XAmple.com
 public Driver(TeamCityApi teamCityApi, WebApplicationApi webApplicationApi, WebFarm webFarm)
 {
     m_TeamCityApi         = teamCityApi;
     m_WebApplicationApi   = webApplicationApi;
     m_WebFarm             = webFarm;
     m_ApplicationVersions = new List <Version>();
 }
コード例 #3
0
        public void BuildsShouldComeBackOrderedByNumericalId()
        {
            var mockClient = A.Fake<IAuthenticatedRestClient>();

            var api = new TeamCityApi(mockClient, new MemoryCacheClient());
            SetMockReturnValues(mockClient, "bt100","98", new List<IssueUsage>());
            SetMockReturnValues(mockClient, "bt100", "99", new List<IssueUsage>());
            SetMockReturnValues(mockClient, "bt100", "100", new List<IssueUsage>
                {
                    new IssueUsage{Issue = new Issue{Id = "TEST-1", Url = "http://test.com/api/test-1"}}
                });
            SetMockReturnValues(mockClient, "bt100", "101", new List<IssueUsage>
                {
                    new IssueUsage{Issue = new Issue{Id = "TEST-2", Url = "http://test.com/api/test-2"}},
                    new IssueUsage{Issue = new Issue{Id = "TEST-3", Url = "http://test.com/api/test-3"}}
                });
            SetMockReturnValues(mockClient, "bt100", "102", new List<IssueUsage>());

            //Construct a build number order that is int but not string correct (crossing length/number boundary
            var issues = api.GetIssuesByBuildTypeAndBuildRange("bt100", "1.0.0.0", "1.0.0.2", new List<Build>
                {
                    new Build {BuildTypeId = "bt100", Id = "98", Number = "0.9.0.0"},
                    new Build {BuildTypeId = "bt100", Id = "99", Number = "1.0.0.0"},
                    new Build {BuildTypeId = "bt100", Id = "100", Number = "1.0.0.1"},
                    new Build {BuildTypeId = "bt100", Id = "101", Number = "1.0.0.2"},
                    new Build {BuildTypeId = "bt100", Id = "102", Number = "1.0.0.3"},
                });

            Assert.AreEqual(3, issues.Count());
        }
        /// <summary>
        /// Attempts to build a a list of PackageBuildMapping objects by interrogating a list of servers.
        /// </summary>
        /// <param name="servers">The servers to query.</param>
        /// <param name="useArtifactsNotPackageSteps">If set, ignore TeamCity NuGet build steps and use the existence of packages in the artifacts as proof of creation.</param>
        public void BuildCache(List<string> servers, bool useArtifactsNotPackageSteps = false)
        {
            foreach (var server in servers)
            {
                var apiConnection = new TeamCityApi(new CachingThreadSafeAuthenticatedRestClient(new MemoryCacheClient(), server, null), new MemoryCacheClient());
                var buildConfigurations = apiConnection.GetBuildTypes();
                StartedServerCheck(this, new ServerCheckEventArgs {Count = buildConfigurations.Count, Url = server});
                foreach (var configuration in buildConfigurations)
                {
                    StartedBuildCheck(this,new BuildMappingEventArgs(){Name = configuration.Name});
                    var packages = useArtifactsNotPackageSteps
                                       ? GetPackageListFromArtifacts(configuration, apiConnection).ToList()
                                       : GetPackageListFromSteps(configuration, apiConnection).ToList();

                    foreach (var package in packages)
                    {
                        PackageBuildMappings.Add(new PackageBuildMapping
                            {
                                BuildConfigurationId = configuration.Id,
                                BuildConfigurationName = configuration.Name,
                                Project = configuration.ProjectName,
                                PackageId = package,
                                ServerUrl = server
                            });
                    }
                    FinishedBuildCheck(this, new BuildMappingEventArgs(){Name = configuration.Name});
                }
                FinishedServerCheck(this, new ServerCheckEventArgs(){Count = buildConfigurations.Count,Url = server});
            }
        }
コード例 #5
0
ファイル: TeamCity.cs プロジェクト: stempy/NuGet.Extensions
        public override void ExecuteCommand()
        {
            //HACK Must be a better way to do this??
            if (string.IsNullOrEmpty(TeamCityServer))
            {
                HelpCommand.Arguments.Add("teamcity");
                HelpCommand.ExecuteCommand();
                return;
            }

            var sw = new Stopwatch();

            sw.Start();
            Console.WriteLine("Attempting to create graph from TeamCity server: {0}", TeamCityServer);
            var api          = new TeamCityApi(TeamCityServer);
            var buildConfigs = string.IsNullOrEmpty(Project)
                                   ? api.GetBuildTypes().ToList()
                                   : api.GetBuildTypes().Where(b => b.ProjectName.Equals(Project, StringComparison.InvariantCultureIgnoreCase)).ToList();

            Console.WriteLine("Processing {0} build configurations...", buildConfigs.Count());
            foreach (var buildConfig in buildConfigs)
            {
                var details = api.GetBuildTypeDetailsById(buildConfig.Id);

                AddSubscribeDataFromTriggers(buildConfig, details);

                if (!NoPublishStep)
                {
                    AddPublishDataFromSteps(buildConfig, details);
                }


                if (!NoArtifact)
                {
                    AddPublishDataFromArtifacts(buildConfig, api);
                }
            }


            if (NoPackageAsVertex)
            {
                BuildGraphWithPackagesAsLabels(_mappings);
                _simpleGraph.ToDirectedGraphML(_simpleGraph.GetVertexIdentity(), _simpleGraph.GetEdgeIdentity(), (s, n) => n.Label = s, (s, e) => e.Label = s.Tag).WriteXml(_outputFilename);
            }
            else
            {
                BuildGraphWithPackagesAsVertices(_mappings);
                _fancyGraph.ToDirectedGraphML(_fancyGraph.GetVertexIdentity(), _fancyGraph.GetEdgeIdentity(), GetNodeFormat(), GetEdgeFormat()).WriteXml(_outputFilename);
            }

            Console.WriteLine();
            sw.Stop();
            OutputElapsedTime(sw);
            Environment.Exit(0);
        }
コード例 #6
0
        public void OnlyFirstRequestForSameItemShouldGoToRestClient()
        {
            var mockClient = A.Fake<IAuthenticatedRestClient>();
            A.CallTo(mockClient).WithReturnType<BuildDetails>().ReturnsLazily(() => new BuildDetails {Id = "5555"});

            var api = new TeamCityApi(mockClient, new MemoryCacheClient());
            api.GetBuildDetailsByBuildId("test");
            api.GetBuildDetailsByBuildId("test");

            A.CallTo(() => mockClient.Execute<BuildDetails>(A<IRestRequest>.Ignored)).MustHaveHappened(Repeated.Exactly.Once);
        }
コード例 #7
0
ファイル: TeamCity.cs プロジェクト: stempy/NuGet.Extensions
 private void AddPublishDataFromArtifacts(BuildType buildConfig, TeamCityApi api)
 {
     //check artifacts..
     //TODO we cant detect feed here, so turn off when feed specific?
     foreach (var artifact in api.GetArtifactListByBuildType(buildConfig.Id).Where(a => a.Ext.Equals("nupkg")))
     {
         var package = Regex.Match(artifact.Name, @".+?(?=(?:(?:[\._]\d+){2,})$)").Value;
         AddBuildPackageMappingIfRequired(buildConfig);
         if (!_mappings[buildConfig.Name].Publishes.Contains(package))
         {
             _mappings[buildConfig.Name].Publishes.Add(package);
         }
     }
 }
コード例 #8
0
        private void ResolveBuildTypeId(TeamCityApi api)
        {
            if (!String.IsNullOrEmpty(BuildType))
            {
                return;
            }
            if (string.IsNullOrEmpty(ProjectName) || string.IsNullOrEmpty(BuildName))
            {
                throw new ApplicationException(String.Format("Could not resolve Project: {0} and BuildName:{1} to a build type", ProjectName, BuildName));
            }
            var resolvedBuildType = api.GetBuildTypeByProjectAndName(ProjectName, BuildName).FirstOrDefault();

            if (resolvedBuildType != null)
            {
                BuildType = resolvedBuildType.Id;
            }
        }
コード例 #9
0
        public override int Run(string[] remainingArguments)
        {
            BuildLight.TurnOffLights();
            AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => BuildLight.TurnOffLights();

            BuildLight.TestLights();
            BuildLight.Disco(2);
            BuildLight.TurnOffLights();
            TeamCityBuildMonitor buildMonitor = null;

            try
            {
                var          lies = new List <string>(_buildLies.ToLowerInvariant().Split(';'));
                ITeamCityApi api  = new TeamCityApi(_serverUrl);
                buildMonitor = new TeamCityBuildMonitor(api, _specificProject, _failOnFirstFailed, lies, _pollInterval, _buildTypeIds);
                const int blinkInterval = 30;
                buildMonitor.CheckFailed += (sender, eventArgs) =>
                {
                    BuildLight.TurnOnFailLight();
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " Failed");
                };
                RegisterBuildEvents(buildMonitor, blinkInterval);
                buildMonitor.CheckSuccessfull += (sender, eventArgs) =>
                {
                    BuildLight.TurnOnSuccessLight();
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " Passed");
                };
                buildMonitor.ServerCheckException += (sender, eventArgs) => Console.WriteLine(DateTime.Now.ToShortTimeString() + " Server unavailable");
                buildMonitor.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.ReadKey();

            if (buildMonitor != null)
            {
                buildMonitor.Stop();
            }
            BuildLight.TurnOffLights();
            return(0);
        }
コード例 #10
0
        /// <summary>
        /// Attempts to build a a list of PackageBuildMapping objects by interrogating a list of servers.
        /// </summary>
        /// <param name="servers">The servers to query.</param>
        /// <param name="useArtifactsNotPackageSteps">If set, ignore TeamCity NuGet build steps and use the existence of packages in the artifacts as proof of creation.</param>
        public void BuildCache(List <string> servers, bool useArtifactsNotPackageSteps = false)
        {
            foreach (var server in servers)
            {
                var apiConnection       = new TeamCityApi(server);
                var buildConfigurations = apiConnection.GetBuildTypes();
                StartedServerCheck(this, new ServerCheckEventArgs()
                {
                    Count = buildConfigurations.Count, Url = server
                });
                foreach (var configuration in buildConfigurations)
                {
                    StartedBuildCheck(this, new BuildMappingEventArgs()
                    {
                        Name = configuration.Name
                    });
                    var packages = useArtifactsNotPackageSteps
                                       ? GetPackageListFromArtifacts(configuration, apiConnection).ToList()
                                       : GetPackageListFromSteps(configuration, apiConnection).ToList();

                    foreach (var package in packages)
                    {
                        PackageBuildMappings.Add(new PackageBuildMapping
                        {
                            BuildConfigurationId   = configuration.Id,
                            BuildConfigurationName = configuration.Name,
                            Project   = configuration.ProjectName,
                            PackageId = package,
                            ServerUrl = server
                        });
                    }
                    FinishedBuildCheck(this, new BuildMappingEventArgs()
                    {
                        Name = configuration.Name
                    });
                }
                FinishedServerCheck(this, new ServerCheckEventArgs()
                {
                    Count = buildConfigurations.Count, Url = server
                });
            }
        }
コード例 #11
0
        public override int Run(string[] remainingArguments)
        {
            ICacheClient client = new MemoryCacheClient();
            var api = new TeamCityApi(new CachingThreadSafeAuthenticatedRestClient(new MemoryCacheClient(), _serverName, _teamCityAuthToken), client);

            var buildPackageCache = string.IsNullOrEmpty(_buildPackageCacheFile) ? null : new PackageBuildMappingCache(_buildPackageCacheFile);

            var issueDetailResolver = new IssueDetailResolver(CreateExternalIssueResolvers());

            var resolver = new AggregateBuildDeltaResolver(api, issueDetailResolver, new PackageChangeComparator(), buildPackageCache, new ConcurrentBag<NuGetPackageChange>());
            _changeManifest = string.IsNullOrEmpty(_buildType)
                ? resolver.CreateChangeManifestFromBuildTypeName(_projectName, _buildName,_referenceBuild, _from, _to, _useBuildSystemIssueResolution, _recurse, _branchName)
                : resolver.CreateChangeManifestFromBuildTypeId(_buildType, _referenceBuild, _from, _to, _useBuildSystemIssueResolution, _recurse, _branchName);

            OutputChanges(CreateOutputRenderers(), new List<Action<string>> {Console.Write, a =>
                {
                    if (!string.IsNullOrEmpty(_outputFileName))
                        File.WriteAllText(_outputFileName, a);
                }});
            return 0;
        }
コード例 #12
0
ファイル: CommandBase.cs プロジェクト: BenPhegan/TeamFlash
        public override int Run(string[] remainingArguments)
        {
            BuildLight.TurnOffLights();
            AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => BuildLight.TurnOffLights();

            BuildLight.TestLights();
            BuildLight.Disco(2);
            BuildLight.TurnOffLights();
            TeamCityBuildMonitor buildMonitor = null;
            try
            {
                var lies = new List<string>(_buildLies.ToLowerInvariant().Split(';'));
                ITeamCityApi api = new TeamCityApi(_serverUrl);
                buildMonitor = new TeamCityBuildMonitor(api, _specificProject, _failOnFirstFailed, lies, _pollInterval, _buildTypeIds);
                const int blinkInterval = 30;
                buildMonitor.CheckFailed += (sender, eventArgs) =>
                {
                    BuildLight.TurnOnFailLight();
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " Failed");
                };
                RegisterBuildEvents(buildMonitor, blinkInterval);
                buildMonitor.CheckSuccessfull += (sender, eventArgs) =>
                {
                    BuildLight.TurnOnSuccessLight();
                    Console.WriteLine(DateTime.Now.ToShortTimeString() + " Passed");
                };
                buildMonitor.ServerCheckException += (sender, eventArgs) => Console.WriteLine(DateTime.Now.ToShortTimeString() + " Server unavailable");
                buildMonitor.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.ReadKey();

            if (buildMonitor != null) buildMonitor.Stop();
            BuildLight.TurnOffLights();
            return 0;
        }
コード例 #13
0
        public override int Run(string[] remainingArguments)
        {
            var api = new TeamCityApi(ServerName);

            if (!string.IsNullOrEmpty(_buildId))
            {
                ChangeDetails = api.GetChangeDetailsByBuildId(_buildId).ToList();
            }
            else
            {
                ChangeDetails = _currentOnly
                                    ? api.GetChangeDetailsForCurrentBuildByBuildType(BuildType).ToList()
                                    : api.GetChangeDetailsForLastBuildByBuildType(BuildType).ToList();
            }

            OutputChanges(CreateOutputRenderers(), new List<Action<string>>()
                {
                    Console.Write,
                    a => File.WriteAllText(OutputFileName,a)
                });
            return 0;
        }
コード例 #14
0
        public override int Run(string[] remainingArguments)
        {
            var api = new TeamCityApi(ServerName);

            if (!string.IsNullOrEmpty(_buildId))
            {
                ChangeDetails = api.GetChangeDetailsByBuildId(_buildId).ToList();
            }
            else
            {
                ChangeDetails = _currentOnly
                                    ? api.GetChangeDetailsForCurrentBuildByBuildType(BuildType).ToList()
                                    : api.GetChangeDetailsForLastBuildByBuildType(BuildType).ToList();
            }

            OutputChanges(CreateOutputRenderers(), new List <Action <string> >()
            {
                Console.Write,
                a => File.WriteAllText(OutputFileName, a)
            });
            return(0);
        }
コード例 #15
0
        private static IEnumerable <string> GetPackageListFromArtifacts(BuildType buildConfig, TeamCityApi api)
        {
            var packages = new List <string>();

            foreach (var artifact in api.GetArtifactListByBuildType(buildConfig.Id).Where(a => a.Ext.Equals("nupkg")))
            {
                var package = Regex.Match(artifact.Name, @".+?(?=(?:(?:[\._]\d+){2,})$)").Value;
                if (!string.IsNullOrEmpty(package))
                {
                    packages.Add(package);
                }
            }
            return(packages);
        }
        private static IEnumerable<string> GetPackageListFromSteps(BuildType buildConfig, TeamCityApi api)
        {
            var packages = new List<string>();
            //Check for nuget publish steps
            var details = api.GetBuildTypeDetailsById(buildConfig.Id);
            var steps = details.Steps.Where(s => s.Type.Equals("jb.nuget.publish"));

            foreach (var packageNames in steps.Select(publishStep => GetPackageNames(publishStep.Properties.First(p => p.Name.Equals("nuget.publish.files")).value)))
            {
                packages.AddRange(packageNames);
            }
            return packages;
        }
 private static IEnumerable<string> GetPackageListFromArtifacts(BuildType buildConfig, TeamCityApi api)
 {
     var packages = new List<string>();
     foreach (var artifact in api.GetArtifactListByBuildType(buildConfig.Id).Where(a => a.Ext.Equals("nupkg")))
     {
         var package = Regex.Match(artifact.Name, @".+?(?=(?:(?:[\._]\d+){2,})$)").Value;
         if (!string.IsNullOrEmpty(package))
             packages.Add(package);
     }
     return packages;
 }
コード例 #18
0
 private void ResolveBuildTypeId(TeamCityApi api)
 {
     if (!String.IsNullOrEmpty(BuildType)) return;
     if (string.IsNullOrEmpty(ProjectName) || string.IsNullOrEmpty(BuildName))
     {
         throw new ApplicationException(String.Format("Could not resolve Project: {0} and BuildName:{1} to a build type", ProjectName, BuildName));
     }
     var resolvedBuildType = api.GetBuildTypeByProjectAndName(ProjectName, BuildName).FirstOrDefault();
     if (resolvedBuildType != null)
         BuildType = resolvedBuildType.Id;
 }
コード例 #19
0
        public override int Run(string[] remainingArguments)
        {
            var api = new TeamCityApi(ServerName);

            ResolveBuildTypeId(api);

            if (string.IsNullOrEmpty(_from))
            {
                var latestSuccesfull = api.GetLatestSuccesfulBuildByBuildType(BuildType);
                if (latestSuccesfull != null)
                    _from = latestSuccesfull.Number;
                else
                    throw new ApplicationException(string.Format("Could not find latest build for build type {0}", BuildType));
            }
            if (string.IsNullOrEmpty(_to))
            {
                var runningBuild = api.GetRunningBuildByBuildType(BuildType).FirstOrDefault();
                if (runningBuild != null)
                    _to = runningBuild.Number;
                else
                    throw new ApplicationException(String.Format("Could not resolve a build number for the running build."));
            }

            var buildWithCommitData = _referenceBuild ?? BuildType;
            var buildTypeDetails = api.GetBuildTypeDetailsById(BuildType);
            var referenceBuildTypeDetails = !string.IsNullOrEmpty(_referenceBuild) ? api.GetBuildTypeDetailsById(_referenceBuild) : null;
            //TODO TFS collection data should come from the BuildType/VCS root data from TeamCity...but not for now...
            if (!string.IsNullOrEmpty(_from) && !string.IsNullOrEmpty(_to) && !string.IsNullOrEmpty(buildWithCommitData))
            {
                var builds = api.GetBuildsByBuildType(buildWithCommitData);
                if (builds != null)
                {
                    var buildList = builds as List<Build> ?? builds.ToList();
                    ChangeDetails = api.GetChangeDetailsByBuildTypeAndBuildNumber(buildWithCommitData, _from, _to, buildList).ToList();
                    IssueDetails = api.GetIssuesByBuildTypeAndBuildRange(buildWithCommitData, _from, _to, buildList).ToList();
                }
            }

            var resolvers = CreateExternalIssueResolvers();

            var issueDetailResolver = new IssueDetailResolver(resolvers);
            var issueDetails = issueDetailResolver.GetExternalIssueDetails(IssueDetails);
            ChangeManifest.ChangeDetails.AddRange(ChangeDetails);
            ChangeManifest.IssueDetails.AddRange(issueDetails);
            ChangeManifest.Generated = DateTime.Now;
            ChangeManifest.FromVersion = _from;
            ChangeManifest.ToVersion = _to;
            ChangeManifest.BuildConfiguration = buildTypeDetails;
            ChangeManifest.ReferenceBuildConfiguration = referenceBuildTypeDetails ?? new BuildTypeDetails();

            OutputChanges(CreateOutputRenderers(),new List<Action<string>>()
                {
                    Console.Write,
                    a =>
                        {
                            if (!string.IsNullOrEmpty(OutputFileName))
                                File.WriteAllText(OutputFileName, a);
                        }
                });
            return 0;
        }
コード例 #20
0
ファイル: Program.cs プロジェクト: CraigRichards/TeamFlash
        static void Main(string[] args)
        {
            var help = false;
            var serverUrl = string.Empty;
            var username = string.Empty;
            var password = string.Empty;
            var guestAuth = false;
            var specificProject = string.Empty;
            bool failOnFirstFailed = false;
            string buildLies = string.Empty;
            double pollInterval = 60000;

            var options = new OptionSet()
                    .Add("?|help|h", "Output options", option => help = option != null)
                    .Add("s=|url=|server=", "TeamCity URL", option => serverUrl = option)
                    .Add("u|user=|username="******"Username", option => username = option)
                    .Add("p|password="******"Password", option => password = option)
                    .Add("g|guest|guestauth", "Connect using anonymous guestAuth", option => guestAuth = option != null)
                    .Add("sp|specificproject=","Constrain to a specific project", option => specificProject = option)
                    .Add("f|failonfirstfailed", "Check until finding the first failed", option => failOnFirstFailed = option != null)
                    .Add("l|lies=","Lie for these builds, say they are green", option => buildLies = option)
                    .Add("i|interval","Time interval in seconds to poll server.", option => pollInterval = option != null ? Convert.ToDouble(option) : 60000);

            try
            {
                options.Parse(args);
            }
            catch (OptionException)
            {
                OutputFailureAndExit(options, "Incorrect arguments, usage is: ");
            }

            if (help)
            {
                Console.WriteLine(options);
                Environment.Exit(0);
            }

            if (string.IsNullOrEmpty(serverUrl))
                OutputFailureAndExit(options, "Must have a Server URL provided");

            if (!guestAuth && string.IsNullOrEmpty(username))
                OutputFailureAndExit(options, "Either provide username/password or use guestAuth = true");

            var monitor = new Monitor();
            monitor.TurnOffLights();
            AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => monitor.TurnOffLights();

            monitor.TestLights();
            monitor.Disco(2);
            monitor.TurnOffLights();
            TeamCityBuildMonitor buildMonitor = null;
            try
            {
                var lies = new List<String>(buildLies.ToLowerInvariant().Split(';'));
                ITeamCityApi api = new TeamCityApi(serverUrl);
                buildMonitor = new TeamCityBuildMonitor(api, specificProject, failOnFirstFailed, lies, pollInterval);
                buildMonitor.CheckFailed += (sender, eventArgs) =>
                    {
                        monitor.TurnOnFailLight();
                        Console.WriteLine(DateTime.Now.ToShortTimeString() + " Failed");
                    };
                buildMonitor.BuildChecked += (sender, eventArgs) => monitor.Blink();
                var blinkInterval = 30;
                buildMonitor.BuildPaused += (sender, eventArgs) => monitor.BlinkThenRevert(LedColour.Yellow,blinkInterval);
                buildMonitor.BuildSkipped += (sender, eventArgs) => monitor.BlinkThenRevert(LedColour.Purple,blinkInterval);
                buildMonitor.BuildSuccess += (sender, eventArgs) => monitor.BlinkThenRevert(LedColour.Green, blinkInterval);
                buildMonitor.BuildFail += (sender, eventArgs) => monitor.BlinkThenRevert(LedColour.Red, blinkInterval);
                buildMonitor.BuildUnknown += (sender, eventArgs) => monitor.BlinkThenRevert(LedColour.Yellow, blinkInterval);
                buildMonitor.CheckSuccessfull += (sender, eventArgs) =>
                    {
                        monitor.TurnOnSuccessLight();
                        Console.WriteLine(DateTime.Now.ToShortTimeString() + " Passed");
                    };
                buildMonitor.ServerCheckException += (sender, eventArgs) => Console.WriteLine(DateTime.Now.ToShortTimeString() + " Server unavailable");
                buildMonitor.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            while (!Console.KeyAvailable)
            {
            }
            if (buildMonitor != null) buildMonitor.Stop();
            monitor.TurnOffLights();
        }
コード例 #21
0
        public override int Run(string[] remainingArguments)
        {
            var api = new TeamCityApi(ServerName);

            ResolveBuildTypeId(api);

            if (string.IsNullOrEmpty(_from))
            {
                var latestSuccesfull = api.GetLatestSuccesfulBuildByBuildType(BuildType);
                if (latestSuccesfull != null)
                {
                    _from = latestSuccesfull.Number;
                }
                else
                {
                    throw new ApplicationException(string.Format("Could not find latest build for build type {0}", BuildType));
                }
            }
            if (string.IsNullOrEmpty(_to))
            {
                var runningBuild = api.GetRunningBuildByBuildType(BuildType).FirstOrDefault();
                if (runningBuild != null)
                {
                    _to = runningBuild.Number;
                }
                else
                {
                    throw new ApplicationException(String.Format("Could not resolve a build number for the running build."));
                }
            }

            var buildWithCommitData       = _referenceBuild ?? BuildType;
            var buildTypeDetails          = api.GetBuildTypeDetailsById(BuildType);
            var referenceBuildTypeDetails = !string.IsNullOrEmpty(_referenceBuild) ? api.GetBuildTypeDetailsById(_referenceBuild) : null;

            //TODO TFS collection data should come from the BuildType/VCS root data from TeamCity...but not for now...
            if (!string.IsNullOrEmpty(_from) && !string.IsNullOrEmpty(_to) && !string.IsNullOrEmpty(buildWithCommitData))
            {
                var builds = api.GetBuildsByBuildType(buildWithCommitData);
                if (builds != null)
                {
                    var buildList = builds as List <Build> ?? builds.ToList();
                    ChangeDetails = api.GetChangeDetailsByBuildTypeAndBuildNumber(buildWithCommitData, _from, _to, buildList).ToList();
                    IssueDetails  = api.GetIssuesByBuildTypeAndBuildRange(buildWithCommitData, _from, _to, buildList).ToList();
                }
            }

            var resolvers = CreateExternalIssueResolvers();


            var issueDetailResolver = new IssueDetailResolver(resolvers);
            var issueDetails        = issueDetailResolver.GetExternalIssueDetails(IssueDetails);

            ChangeManifest.ChangeDetails.AddRange(ChangeDetails);
            ChangeManifest.IssueDetails.AddRange(issueDetails);
            ChangeManifest.Generated                   = DateTime.Now;
            ChangeManifest.FromVersion                 = _from;
            ChangeManifest.ToVersion                   = _to;
            ChangeManifest.BuildConfiguration          = buildTypeDetails;
            ChangeManifest.ReferenceBuildConfiguration = referenceBuildTypeDetails ?? new BuildTypeDetails();


            OutputChanges(CreateOutputRenderers(), new List <Action <string> >()
            {
                Console.Write,
                a =>
                {
                    if (!string.IsNullOrEmpty(OutputFileName))
                    {
                        File.WriteAllText(OutputFileName, a);
                    }
                }
            });
            return(0);
        }
コード例 #22
0
        private static IEnumerable <string> GetPackageListFromSteps(BuildType buildConfig, TeamCityApi api)
        {
            var packages = new List <string>();
            //Check for nuget publish steps
            var details = api.GetBuildTypeDetailsById(buildConfig.Id);
            var steps   = details.Steps.Where(s => s.Type.Equals("jb.nuget.publish"));

            foreach (var packageNames in steps.Select(publishStep => GetPackageNames(publishStep.Properties.First(p => p.Name.Equals("nuget.publish.files")).value)))
            {
                packages.AddRange(packageNames);
            }
            return(packages);
        }