public List <Build> RunningByBuildConfigId(string buildConfigId) { return(ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId)), new List <string> { "running:true" })); }
private void RefreshInfo(Refresh msg) { var info = _currentBuildInfo; var client = Connect(); var builds = client.Builds.ByBuildLocator( BuildLocator.WithDimensions( BuildTypeLocator.WithId(_buildTypeId), sinceDate: DateTime.Today.AddDays(-4), branch: "trunk")); var lastBuild = builds.Last(); var build = client.Builds.ById(lastBuild.Id); var status = build.Running ? BuildStatus.Running : "SUCCESS".Equals(build.Status, StringComparison.OrdinalIgnoreCase) ? BuildStatus.Success : BuildStatus.Failed; info.Name = string.IsNullOrWhiteSpace(build.BranchName) ? build.BuildType.Name : $"{build.BuildType.Name}|{build.BranchName}"; info.Number = build.Number; info.Status = status; info.Url = build.WebUrl; info.CompletedOn = build.FinishDate; info.ProjectName = build.BuildType.ProjectName; info.StartedBy = build.Triggered.User.Username; info.StartedOn = build.StartDate; info.StatusText = build.StatusText; SendBuildInfoMessage(); }
private void ReadBuildStatus(object buildConfigurationIdObject) { var buildConfigurationId = buildConfigurationIdObject as string; try { Build buildInformation; string name; lock (_lock) { if (_useDefault) { buildInformation = _client.Builds.LastBuildByBuildConfigId(buildConfigurationId); } else { var locator = BuildLocator.WithDimensions(buildType: BuildTypeLocator.WithId(buildConfigurationId)); var builds = _client.Builds.ByBuildLocator(locator); buildInformation = builds != null?builds.FirstOrDefault() : new Build(); } var configuration = _client.BuildConfigs.ByConfigurationId(buildConfigurationId); name = configuration.Name ?? buildConfigurationId; } OnReadBuildStatusComplete(buildInformation.Status == "SUCCESS" ? BuildStatus.Success : BuildStatus.Failed, buildConfigurationId, name); } catch (Exception ex) { OnReadBuildStatusError(ex, buildConfigurationId); } }
public Build LastBuildByBuildConfigId(string buildConfigId) { var builds = ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), maxResults: 1 )); return(builds != null?builds.FirstOrDefault() : new Build()); }
public void AddJob(string buildRegressionId, string teamcityIncludeParameterName, string includingCases) { if (!string.IsNullOrEmpty(includingCases)) { TeamCityManager.Instance.BuildConfigs.SetConfigurationParameter(BuildTypeLocator.WithId(buildRegressionId), teamcityIncludeParameterName, includingCases); TeamCityManager.Instance.Builds.Add2QueueBuildByBuildConfigId(buildRegressionId); } }
public void it_returns_build_config_templates() { string buildConfigId = m_goodBuildConfigId; var buildLocator = BuildTypeLocator.WithId(buildConfigId); var templates = m_client.BuildConfigs.GetTemplates(buildLocator); Assert.IsNotNull(templates, "No templates found, invalid templates call."); }
public void it_modify_artifact_dependencies() { const string depend = "TeamcityDashboardScenario_Test_TestWithCheckout"; const string newDepend = "TeamcityDashboardScenario_Test_TestWithCheckoutWithDependencies"; var buildLocatorFinal = new BuildTypeLocator(); try { var buildConfig = m_client.BuildConfigs.CreateConfigurationByProjectId(m_goodProjectId, "testNewConfig"); buildLocatorFinal = BuildTypeLocator.WithId(buildConfig.Id); var artifactDependencies = new ArtifactDependencies { ArtifactDependency = new List <ArtifactDependency> { new ArtifactDependency { Id = "TTTT_100", Type = "artifact_dependency", SourceBuildType = new BuildConfig { Id = depend }, Properties = new Properties { Property = new List <Property> { new Property { Name = "cleanDestinationDirectory", Value = "false" }, new Property { Name = "pathRules", Value = "step1.txt" }, new Property { Name = "revisionName", Value = "lastSuccessful" }, new Property { Name = "revisionValue", Value = "latest.lastSuccessful" } } } } } }; m_client.BuildConfigs.SetArtifactDependency(buildLocatorFinal, artifactDependencies.ArtifactDependency[0]); m_client.BuildConfigs.ModifArtifactDependencies(buildConfig.Id, depend, newDepend); } catch (Exception e) { Console.WriteLine(e); throw; } finally { //Cleanup m_client.BuildConfigs.DeleteConfiguration(buildLocatorFinal); } }
public Build LastFailedBuildByBuildConfigId(string buildConfigId, List <String> param = null) { var builds = ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), status: BuildStatus.FAILURE, maxResults: 1 ), param); return(builds != null?builds.FirstOrDefault() : new Build()); }
public Build LastSuccessfulBuildByBuildConfigId(string buildConfigId) { var builds = ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), status: BuildStatus.SUCCESS, maxResults: 1 )); return(builds != null?builds.FirstOrDefault() : new Build()); }
public void it_pauses_configuration() { string buildConfigId = m_goodBuildConfigId; var buildLocator = BuildTypeLocator.WithId(buildConfigId); m_client.BuildConfigs.SetConfigurationPauseStatus(buildLocator, true); var status = m_client.BuildConfigs.GetConfigurationPauseStatus(buildLocator); Assert.That(status == true, "Build not paused"); }
public void it_unpauses_configuration() { string buildConfigId = "bt437"; var buildLocator = BuildTypeLocator.WithId(buildConfigId); _client.BuildConfigs.SetConfigurationPauseStatus(buildLocator, false); var status = _client.BuildConfigs.GetConfigurationPauseStatus(buildLocator); Assert.That(status == false, "Build not unpaused"); }
public void it_getraw_build_config_steps() { var bt = new BuildConfig(); try { bt = m_client.BuildConfigs.CreateConfigurationByProjectId(m_goodProjectId, "testNewConfig"); const string xml = @"<steps> <step name=""Test1"" type=""simpleRunner""> <properties> <property name=""script.content"" value=""@echo off
echo Step1
touch step1.txt"" /> <property name=""teamcity.step.mode"" value=""default"" /> <property name=""use.custom.script"" value=""true"" /> </properties> </step> <step name=""Test2"" type=""simpleRunner""> <properties> <property name=""script.content"" value=""@echo off
echo Step1
touch step2.txt"" /> <property name=""teamcity.step.mode"" value=""default"" /> <property name=""use.custom.script"" value=""true"" /> </properties> </step> </steps>"; m_client.BuildConfigs.PutRawBuildStep(BuildTypeLocator.WithId(bt.Id), xml); var newSteps = m_client.BuildConfigs.GetRawBuildStep(BuildTypeLocator.WithId(bt.Id)); var currentStepBuild = newSteps.Step[0]; Assert.That(currentStepBuild.Type == "simpleRunner" && currentStepBuild.Name == "Test1" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "script.content").Value == "@echo off\necho Step1\ntouch step1.txt" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "teamcity.step.mode").Value == "default" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "use.custom.script").Value == "true"); currentStepBuild = newSteps.Step[1]; Assert.That(currentStepBuild.Type == "simpleRunner" && currentStepBuild.Name == "Test2" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "script.content").Value == "@echo off\necho Step1\ntouch step2.txt" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "teamcity.step.mode").Value == "default" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "use.custom.script").Value == "true"); } catch (Exception e) { Assert.Fail($"{e.Message}", e); } finally { m_client.BuildConfigs.DeleteConfiguration(BuildTypeLocator.WithId(bt.Id)); } }
public void it_does_not_populate_the_status_text_field_of_the_build_object() { const string buildConfigId = "bt123"; var build = _client.Builds.ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), maxResults: 1)); Assert.That(build.Count == 1); Assert.IsNull(build[0].StatusText); }
public void Reading_the_status_of_a_non_default_build() { // Given CreateClient(); var expectedBuildInfo = new Build() { Status = "SUCCESS" }; string expectedBuildConfigurationId = "BuildServer_Branch"; var locator = BuildLocator.WithDimensions( buildType: BuildTypeLocator.WithId(expectedBuildConfigurationId), maxResults: 1, branch: "branched:true"); var mockBuilds = ExpectReadOfBuildStatus(expectedBuildConfigurationId, expectedBuildInfo, locator: locator); ExpectReadOfBuildConfiguration(expectedBuildConfigurationId, expectedBuildConfigurationId + "_hello"); var server = new TeamCityServer("localhost", "Username", "Password"); var wait = new System.Threading.AutoResetEvent(false); BuildStatus?actualStatus = null; string actualBuildConfigurationId = null; System.Threading.Thread actualThread = null; string actualName = null; server.ReadBuildStatusComplete += (sender, e) => { actualThread = System.Threading.Thread.CurrentThread; actualStatus = e.Status; actualBuildConfigurationId = e.BuildConfigurationId; actualName = e.Name; wait.Set(); }; server.UseDefault = false; // Set the server to not use the builds default branch // When server.ReadBuildStatusAsync(expectedBuildConfigurationId); Assert.IsTrue(wait.WaitOne(5000)); // Then clientMock.VerifyAll(); mockBuilds.VerifyAll(); Assert.AreEqual(BuildStatus.Success, actualStatus); Assert.AreEqual(expectedBuildConfigurationId, actualBuildConfigurationId); Assert.AreEqual(expectedBuildConfigurationId + "_hello", actualName); Assert.AreNotEqual(System.Threading.Thread.CurrentThread, actualThread); }
public void it_downloads_build_configuration() { string buildConfigId = m_goodBuildConfigId; string directory = Directory.GetCurrentDirectory(); string destination = Path.Combine(directory, "config.txt"); var buildLocator = BuildTypeLocator.WithId(buildConfigId); m_client.BuildConfigs.DownloadConfiguration(buildLocator, tempfile => System.IO.File.Move(tempfile, destination)); Assert.IsTrue(System.IO.File.Exists(destination)); Assert.IsTrue(new FileInfo(destination).Length > 0); }
public Task StartBot(ISkypeAdapter skype, ITeamCityClient teamCity, BotParameters botParameters, Dictionary <string, string> moduleParameters, TimeConfig timeConfig) { _working = true; _skype = skype; _teamcity = teamCity; _botParameters = botParameters; _timeConfig = timeConfig; var task = Task.Run(delegate { try { _publishChat = _skype.GetChat(botParameters.PublishChatName); if (_publishChat != null) { Console.WriteLine("publish chat found!"); } else { Console.WriteLine("publish chat NOT found!"); } _skype.OnMessageReceived += OnMessageReceived; _timer = new Timer { Interval = timeConfig.BuildCheckInterval.TotalMilliseconds }; _timer.Elapsed += timer_Elapsed; _timer.AutoReset = false; _timer.Start(); while (_working) { Thread.Sleep(5); } } catch (Exception ex) { Console.WriteLine("top lvl exception : " + ex); } }); buildCheckers = _botParameters.Branches.Select( x => new TeamCityBuildChecker( BuildLocator.WithDimensions(BuildTypeLocator.WithId(_botParameters.BuildConfigId), branch: x), _teamcity, x, _timeConfig)).ToList(); _bot = new HelloBot(moduleParameters, buildCheckers, MailSettingsSectionGroup => SendMessage(MailSettingsSectionGroup, _publishChat)); _bot.OnErrorOccured += BotOnErrorOccured; return(task); }
public void it_does_not_populate_the_status_text_field_of_the_build_object() { const string buildConfigId = "bt5"; var client = new TeamCityClient("localhost:81"); client.Connect("admin", "qwerty"); var build = client.Builds.ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), maxResults: 1)); Assert.That(build.Count == 1); Assert.IsNull(build[0].StatusText); }
public void it_does_not_populate_the_status_text_field_of_the_build_object() { string buildConfigId = m_goodBuildConfigId; var client = new TeamCityClient(m_server, m_useSsl); client.ConnectAsGuest(); var build = client.Builds.ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), maxResults: 1)); Assert.That(build.Count == 1); Assert.IsNull(build[0].StatusText); }
public void it_modify_build_config() { const string depend = "TeamcityDashboardScenario_Test_TestWithCheckout"; const string newDepend = "TeamcityDashboardScenario_Test_TestWithCheckoutWithDependencies"; try { var buildConfig = m_client.BuildConfigs.CreateConfigurationByProjectId(m_goodProjectId, "testNewConfig"); var buildLocator = BuildTypeLocator.WithId(buildConfig.Id); var bt = new BuildTrigger { Id = "ttt1", Type = "buildDependencyTrigger", Properties = new Properties { Property = new List <Property> { new Property { Name = "afterSuccessfulBuildOnly", Value = "true" }, new Property { Name = "dependsOn", Value = depend } } } }; // Configure starting trigger m_client.BuildConfigs.SetTrigger(buildLocator, bt); var actualFirst = m_client.BuildConfigs.ByConfigurationId(buildConfig.Id); Assert.That(actualFirst.Triggers.Trigger[0].Type == "buildDependencyTrigger" && actualFirst.Triggers.Trigger[0].Properties.Property.FirstOrDefault(x => x.Name == "dependsOn") .Value == depend); // Modify trigger m_client.BuildConfigs.ModifTrigger(buildConfig.Id, depend, newDepend); var actualTwo = m_client.BuildConfigs.ByConfigurationId(buildConfig.Id); Assert.That(actualTwo.Triggers.Trigger[0].Type == "buildDependencyTrigger" && actualTwo.Triggers.Trigger[0].Properties.Property.FirstOrDefault(x => x.Name == "dependsOn") .Value == newDepend); var buildLocatorFinal = BuildTypeLocator.WithId(buildConfig.Id); //Cleanup m_client.BuildConfigs.DeleteConfiguration(buildLocatorFinal); } catch (Exception e) { Assert.Fail($"{e.Message}", e); } }
public void it_create_build_config_step() { var bt = m_client.BuildConfigs.CreateConfigurationByProjectId(m_goodProjectId, "testNewConfig"); var xml = "<step type=\"simpleRunner\">" + "<properties>" + "<property name=\"script.content\" value=\"@echo off
echo Step1
touch step1.txt\" />" + "<property name=\"teamcity.step.mode\" value=\"default\" />" + "<property name=\"use.custom.script\" value=\"true\" />" + "</properties>" + "</step>"; m_client.BuildConfigs.PostRawBuildStep(BuildTypeLocator.WithId(bt.Id), xml); m_client.BuildConfigs.DeleteConfiguration(BuildTypeLocator.WithId(bt.Id)); }
private async Task <bool> IsRunningABuild(string buildId) { Logger.Debug("Retrieving from TeamCity if {buildId} is running", buildId); return(await Task.Run(() => { try { return _client .Builds .ByBuildLocator(BuildLocator.WithDimensions(buildType: BuildTypeLocator.WithId(buildId), running: true)) .Count > 0; } catch (Exception ex) { Logger.Error(ex, "Error retrieving from TeamCity if {buildId} is running", buildId); } return false; })); }
public void it_throws_exception_pauses_configuration_forbidden() { string buildConfigId = m_goodBuildConfigId; var buildLocator = BuildTypeLocator.WithId(buildConfigId); try { var client = new TeamCityClient(m_server, m_useSsl); client.ConnectAsGuest(); client.BuildConfigs.SetConfigurationPauseStatus(buildLocator, true); } catch (HttpException e) { Assert.That(e.ResponseStatusCode == HttpStatusCode.Forbidden); } catch (Exception e) { Assert.Fail($"Set configurationPauseStatus faced an unexpected exception", e); } }
public void it_attaches_templates_to_build_config() { string buildConfigId = m_goodBuildConfigId; var buildLocator = BuildTypeLocator.WithId(buildConfigId); var buildConfig = new Template { Id = m_goodTemplateId }; var buildConfigList = new List <Template>() { buildConfig }; var templates = new Templates { BuildType = buildConfigList }; m_client.BuildConfigs.AttachTemplates(buildLocator, templates); var templatesReceived = m_client.BuildConfigs.GetTemplates(buildLocator); Assert.That(templatesReceived.BuildType.Any(), "Templates not attached"); }
private BuildStatus GetStatus(string buildTypeId) { var pendingChanges = this.teamCityClient.Changes.ByBuildConfigId(buildTypeId).FirstOrDefault(); var queuedBuild = this.teamCityClient.BuildQueue.ByBuildTypeLocator(BuildTypeLocator.WithId(buildTypeId)).FirstOrDefault(); var runningBuild = this.teamCityClient.Builds.ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildTypeId), running: true)).FirstOrDefault(); var lastBuild = this.teamCityClient.Builds .GetFields(BuildsField .WithFields(BuildField.WithFields( true, true, changes: ChangesField.WithFields(ChangeField.WithFields(true)), status: true)) .ToString()).ByBuildConfigId(buildTypeId).OrderByDescending(x => x.Number).FirstOrDefault(); if (lastBuild != null) { return(new BuildStatus(queuedBuild != null | runningBuild != null | GetHasPendingChanges(pendingChanges, lastBuild), lastBuild.Status)); } return(new BuildStatus(false, "None")); }
public void it_create_build_config_step() { var bt = new BuildConfig(); try { bt = m_client.BuildConfigs.CreateConfigurationByProjectId(m_goodProjectId, "testNewConfig"); var xml = "<step type=\"simpleRunner\">" + "<properties>" + "<property name=\"script.content\" value=\"@echo off
echo Step1
touch step1.txt\" />" + "<property name=\"teamcity.step.mode\" value=\"default\" />" + "<property name=\"use.custom.script\" value=\"true\" />" + "</properties>" + "</step>"; m_client.BuildConfigs.PostRawBuildStep(BuildTypeLocator.WithId(bt.Id), xml); var newBt = m_client.BuildConfigs.ByConfigurationId(bt.Id); var currentStepBuild = newBt.Steps.Step[0]; Assert.That(currentStepBuild.Type == "simpleRunner" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "script.content").Value == "@echo off\necho Step1\ntouch step1.txt" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "teamcity.step.mode").Value == "default" && currentStepBuild.Properties.Property.FirstOrDefault(x => x.Name == "use.custom.script").Value == "true"); } catch (Exception e) { Assert.Fail($"{e.Message}", e); } finally { m_client.BuildConfigs.DeleteConfiguration(BuildTypeLocator.WithId(bt.Id)); } }
public void it_creates_build_configuration() { var currentBuildId = "testId"; var buildProject = new Project() { Id = m_goodProjectId }; var parameters = new Parameters { Property = new List <Property>() { new Property() { Name = "category", Value = "test" } } }; var buildConfig = new BuildConfig() { Id = currentBuildId, Name = "testNewConfig", Project = buildProject, Parameters = parameters }; try { buildConfig = m_client.BuildConfigs.CreateConfiguration(buildConfig); Assert.That(buildConfig.Id == currentBuildId); } catch (Exception e) { Assert.Fail($"{e.Message}", e); } finally { m_client.BuildConfigs.DeleteConfiguration(BuildTypeLocator.WithId(currentBuildId)); } }
public void it_returns_build_config_templates_property() { string buildConfigId = m_goodBuildConfigId; var buildLocator = BuildTypeLocator.WithId(buildConfigId); var buildConfig = new Template { Id = m_goodTemplateId }; var buildConfigList = new List <Template>() { buildConfig }; var templates = new Templates { BuildType = buildConfigList }; m_client.BuildConfigs.AttachTemplates(buildLocator, templates); var templatesReceived = m_client.BuildConfigs.GetTemplates(buildLocator); Assert.That(templatesReceived.BuildType.Any(), "Templates not attached"); var templatesField = m_client.BuildConfigs.ByConfigurationId(buildConfigId).Templates; Assert.IsNotNull(templatesField, "Templates property not retrieved correctly"); }
public void it_returns_the_builds_queued_by_build_config_id() { var result = m_client.BuildQueue.ByBuildTypeLocator(BuildTypeLocator.WithId(m_queuedBuildConfigId)); Assert.IsNotEmpty(result); }
public List <Build> ErrorBuildsByBuildConfigId(string buildConfigId) { return(ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), status: BuildStatus.ERROR ))); }
public List <Build> FailedBuildsByBuildConfigId(string buildConfigId) { return(ByBuildLocator(BuildLocator.WithDimensions(BuildTypeLocator.WithId(buildConfigId), status: BuildStatus.FAILURE ))); }