public NotifyCaretakersOfCurrentlyFailedBuilds() : base( "notify caretakers of failed builds$", "`notify caretakers of failed builds` - Send a private message to each caretaker if there are currently failed builds") { client = new TeamCity(Constants.BuildServerRoot); }
public void Run() { var client = new TeamCity(Constants.BuildServerRoot); var projects = client.ListProjects(); var projectWithFailures = projects.SelectMany(p => client.ListCurrentBuilds(p.Id, new[] { "master", "develop" })) .Where(b => b.Status == BuildStatus.Failed) .GroupBy(b => b.Project) .ToList(); Console.Out.WriteLine("Currently failed builds"); foreach (var project in projectWithFailures) { Console.Out.WriteLine(""); Console.Out.WriteLine("### " + project.Key.Name); Console.Out.WriteLine(""); var buildTypes = project.GroupBy(b => b.BuildType); foreach (var buildType in buildTypes) { Console.Out.WriteLine("* `" + buildType.Key + "`"); foreach (var failedBuild in buildType) { Console.Out.WriteLine(" - [{0} - {1}]({2})", failedBuild.Number, failedBuild.Branch, failedBuild.Url); } } } }
public void Commit_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given var ev = new Mock <IEnviornmentVariables>(); ev.Setup(s => s.GetEnvironmentVariable("TEAMCITY_BUILD_COMMIT")).Returns("4491f681062057a9021199f3d19dfa3c3598d43c"); var teamCity = new TeamCity(ev.Object); // When var commit = teamCity.Commit; // Then commit.Should().Be("4491f681062057a9021199f3d19dfa3c3598d43c"); }
public void Shh_Slug_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given var ev = new Mock <IEnviornmentVariables>(); ev.Setup(s => s.GetEnvironmentVariable("TEAMCITY_BUILD_REPOSITORY")).Returns("[email protected]:larzw/codecov-exe.git"); var teamCity = new TeamCity(ev.Object); // When var slug = teamCity.Slug; // Then slug.Should().Be("larzw/codecov-exe"); }
public void Detecter_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits_Or_Is_Empty(string teamCityData) { // Given var ev = new Mock <IEnviornmentVariables>(); ev.Setup(s => s.GetEnvironmentVariable("TEAMCITY_VERSION")).Returns(teamCityData); var teamCity = new TeamCity(ev.Object); // When var detecter = teamCity.Detecter; // Then detecter.Should().BeFalse(); }
public void Detecter_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given var ev = new Mock <IEnviornmentVariables>(); ev.Setup(s => s.GetEnvironmentVariable("TEAMCITY_VERSION")).Returns("true"); var teamCity = new TeamCity(ev.Object); // When var detecter = teamCity.Detecter; // Then detecter.Should().BeTrue(); }
public void BuildUrl_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given Environment.SetEnvironmentVariable("TEAMCITY_BUILD_URL", "www.google.com/hello"); var teamCity = new TeamCity(); // When var build = teamCity.BuildUrl; // Then build.Should().Be("www.google.com%2Fhello"); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_BUILD_URL", null); }
public void Build_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given Environment.SetEnvironmentVariable("TEAMCITY_BUILD_ID", "123"); var teamCity = new TeamCity(); // When var build = teamCity.Build; // Then build.Should().Be("123"); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_BUILD_ID", null); }
public void Branch_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given Environment.SetEnvironmentVariable("TEAMCITY_BUILD_BRANCH", "develop"); var teamCity = new TeamCity(); // When var branch = teamCity.Branch; // Then branch.Should().Be("develop"); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_BUILD_BRANCH", null); }
public void Shh_Slug_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given Environment.SetEnvironmentVariable("TEAMCITY_BUILD_REPOSITORY", "[email protected]:larzw/codecov-exe.git"); var teamCity = new TeamCity(); // When var slug = teamCity.Slug; // Then slug.Should().Be("larzw/codecov-exe"); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_BUILD_REPOSITORY", null); }
public void Detecter_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given Environment.SetEnvironmentVariable("TEAMCITY_VERSION", "true"); var teamCity = new TeamCity(); // When var detecter = teamCity.Detecter; // Then detecter.Should().BeTrue(); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); }
public void Detecter_Should_Be_Empty_String_When_Enviornment_Variable_Does_Not_Exits_Or_Is_Empty(string teamCityData) { // Given Environment.SetEnvironmentVariable("TEAMCITY_VERSION", teamCityData); var teamCity = new TeamCity(); // When var detecter = teamCity.Detecter; // Then detecter.Should().BeFalse(); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_VERSION", null); }
public async Task <List <Project> > GetProjects() { if (TeamCity == null) { return(null); } var allProjects = await TeamCity.GetAllProjectsAsync(); if (allProjects != null) { allProjects.Sort((x, y) => string.Compare(x.Name, y.Name, StringComparison.OrdinalIgnoreCase)); } return(allProjects); }
public async Task LoadArtifacts(string configId) { Artifacts = new List <ArtifactProperties>(); var deps = await TeamCity.GetArtifactDependenciesAsync(configId); if (deps != null) { foreach (var dep in deps) { if (dep.Properties != null) { Artifacts.Add(new ArtifactProperties(dep.Properties)); } } } }
public void Commit_Should_Be_Set_When_Enviornment_Variable_Exits() { // Given Environment.SetEnvironmentVariable("TEAMCITY_BUILD_COMMIT", "4491f681062057a9021199f3d19dfa3c3598d43c"); Environment.SetEnvironmentVariable("BUILD_VCS_NUMBER", null); var teamCity = new TeamCity(); // When var commit = teamCity.Commit; // Then commit.Should().Be("4491f681062057a9021199f3d19dfa3c3598d43c"); // Clean up Environment.SetEnvironmentVariable("TEAMCITY_BUILD_COMMIT", null); }
public IBuildEngine GetBuildEngine() { IBuildEngine engine; if (!string.IsNullOrEmpty(TeamCityUrl)) { engine = new TeamCity(new Uri(TeamCityUrl), TeamCityUsername, TeamCityPassword); } else if (!string.IsNullOrEmpty(CCNetServerUsername)) { engine = new ManualCCNet(CCNetUrl, CCNetServer, CCNetUser, CCNetSource, new System.Net.NetworkCredential(CCNetServerUsername, CCNetServerPassword)); } else { engine = new ManualCCNet(CCNetUrl, CCNetServer, CCNetUser, CCNetSource); } return(engine); }
public static void Main(string[] args) { var teamCity = new TeamCity(args[0], args[1], args[2]); var build = teamCity.Builds.Get(583319); var builds = teamCity.Builds.Find( By.Build.QueuedDateAfter(DateTime.Now.AddDays(-1)), Include.Build .BuildType() .Triggered() .LastChanges() .Agent() .Properties()); var queuedBuilds = teamCity.QueuedBuilds.Find(Include.Build.QueuedDate()); var queuedBuild = teamCity.QueuedBuilds.Run("Build_Type_Id", comment: "Test build from API"); Console.ReadLine(); }
public override bool Execute() { var gitFolder = GitDirFinder.TreeWalkForGitDir(ProjectFolder); if (string.IsNullOrEmpty(gitFolder)) { if (TeamCity.IsRunningInBuildAgent()) //fail the build if we're on a TC build agent { this.LogError("Failed to find .git directory on agent. Please make sure agent checkout mode is enabled for you VCS roots - http://confluence.jetbrains.com/display/TCD8/VCS+Checkout+Mode"); return(false); } var message = string.Format("No .git directory found in solution path '{0}'. This means the assembly may not be versioned correctly. To fix this warning either clone the repository using git or remove the `GitFlowVersion.Fody` nuget package. To temporarily work around this issue add a AssemblyInfo.cs with an appropriate `AssemblyVersionAttribute`.", ProjectFolder); this.LogWarning(message); return(true); } var versionAndBranch = VersionCache.GetVersion(gitFolder); WriteTeamCityParameters(versionAndBranch); var semanticVersion = versionAndBranch.Version; Version = string.Format("{0}.{1}.{2}", semanticVersion.Major, semanticVersion.Minor, semanticVersion.Patch); FileVersion = string.Format("{0}.{1}.{2}", semanticVersion.Major, semanticVersion.Minor, semanticVersion.Patch); InfoVersion = versionAndBranch.ToLongString(); NugetVersion = NugetVersionBuilder.GenerateNugetVersion(versionAndBranch); this.LogInfo(String.Format("Version number is {0} and InfoVersion is {1}", Version, InfoVersion)); if (Files == null) { return(true); } var task = new UpdateAssemblyInfo(Files, Version, FileVersion); task.Execute(); return(true); }
public static void Main(string[] args) { var teamCity = new TeamCity(args[0], args[1], args[2]); var build = teamCity.Builds.Get(106731); Console.WriteLine(build.Number); var builds = teamCity.Builds.Find( By.Build.QueuedDateAfter(DateTime.Now.AddDays(-1)), Include.Build .BuildType() .Triggered() .LastChanges() .Agent() .Properties()); Console.WriteLine(builds.Count); var queuedBuilds = teamCity.QueuedBuilds.Find(Include.Build.QueuedDate()); Console.ReadLine(); }
private TeamCityOutputSink(TeamCity teamCity) { _teamCity = teamCity; }
public void SetUp() { var sp = ConfigureServices(services => services.AddSingleton <TeamCity>()); this.buildServer = sp.GetService <TeamCity>(); }
private ChangesRootObject GetChanges(TeamCity.ChangeRootObject id) { try { using (ServiceStack.JsonServiceClient client = new ServiceStack.JsonServiceClient(parameters.Host)) { client.SetCredentials(parameters.User, parameters.Password); client.AlwaysSendBasicAuthHeader = true; ChangesRootObject b = client.Get<ChangesRootObject>(id.change[0].href); return b; } } catch (Exception e) { logger.Exception(e, "GetChanges", ""); return null; } }
private ArtifcatsRootObject GetArtifact(TeamCity.BuildRootObject id) { try { using (ServiceStack.JsonServiceClient client = new ServiceStack.JsonServiceClient(parameters.Host)) { client.SetCredentials(parameters.User, parameters.Password); client.AlwaysSendBasicAuthHeader = true; ArtifcatsRootObject b = client.Get<ArtifcatsRootObject>(id.artifacts.href); return b; } } catch (Exception e) { logger.Exception(e, "GetArtifact", ""); return null; } }
internal TeamCityOutputSink(TeamCity teamCity) { _teamCity = teamCity; }
public override async Task Execute(string[] parameters, IResponse response) { var projectName = parameters[1]; IEnumerable<Project> projects; var client = new TeamCity(Constants.BuildServerRoot); var allProjects = client.ListProjects(); var displaySuccessMessage = true; switch (projectName) { case "all projects": projects = allProjects; displaySuccessMessage = false; break; case "my repos": var username = response.User.Name; var repoNames = Brain.Get<AvailableRepositories>() .Where(r => r.Caretaker == username) .Select(r => r.Name) .ToList(); projects = allProjects.Where(p => repoNames.Any(r => r == p.Name)); break; default: var project = allProjects.FirstOrDefault(p => p.Name == projectName); if (project == null) { await response.Send($"No build with name `{projectName}` could be found on the buildserver"); return; } projects = new[] { project }; break; } var projectWithFailures = projects.SelectMany(p => client.ListCurrentBuilds(p.Id, new[] { "master", "develop" })) .Where(b => b.Status == BuildStatus.Failed) .GroupBy(b => b.Project) .ToList(); foreach (var project in projectWithFailures) { var sb = new StringBuilder(); sb.AppendLine("*" + project.Key.Name + "*"); var buildTypes = project.GroupBy(b => b.BuildType); foreach (var buildType in buildTypes) { sb.AppendLine("* `" + buildType.Key + "`"); foreach (var failedBuild in buildType) { sb.AppendLine($" - {failedBuild.Number}({failedBuild.Branch}) {failedBuild.Url}"); } } await response.Send(sb.ToString()); } if (projectWithFailures.Count > 0) { var totalDownTimeT = projectWithFailures.SelectMany(p => p.Select(bt => DateTime.Now - client.GetBuild(bt.Id).FinishedAt)).ToList(); var totalDownTime = totalDownTimeT.Sum(ts => ts.TotalDays); await response.Send($"Summary: {projectWithFailures.SelectMany(p => p).Count()} failed builds, Total down time: {totalDownTime} days"); } if (projectWithFailures.Count == 0 && displaySuccessMessage) { await response.Send("All builds green for: " + string.Join(",", projects.Select(p => p.Name))); } }
public Task <List <BuildType> > GetConfigurationsForProjectTask(string projectId) { return(TeamCity.GetBuildTypesForProjectTask(projectId)); }
public void TestTeamCity(PropertyInfo property, TeamCity instance) { AssertProperty(instance, property); }
public DisplayBuildsController(TeamCity.BuildAccess teamCityBuild) { _teamCityBuild = teamCityBuild; }