public void TeamCityBuildStatus_PassingBuildNoComment()
        {
            var teamCityFailingBuild  = TeamCityResources.TeamCityFailingBuild;
            var teamCityFailingChange = TeamCityResources.TeamCityFailingChange;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting
            {
                Name = "Name",
                Id   = "BuildDefinitionId"
            };
            var buildStatus = new TeamCityBuildStatus(buildDefinitionSetting, teamCityFailingBuild, teamCityFailingChange);

            Assert.AreEqual(BuildStatusEnum.Broken, buildStatus.BuildStatusEnum);
            Assert.AreEqual("BuildDefinitionId", buildStatus.BuildDefinitionId);
            Assert.AreEqual("BuildConfig4", buildStatus.Name);
            Assert.AreEqual("lee", buildStatus.RequestedBy);
            Assert.AreEqual(new DateTime(2012, 1, 27, 0, 15, 45, 0), buildStatus.StartedTime, HudsonBuildStatusTest.DateAsCode(buildStatus.StartedTime.Value));
            string expectedComment = @"Merge branch 'master' of C:\dev\CiTest

Conflicts:
	CiTest/Program.cs"    .Replace("\r", "");

            Assert.AreEqual(expectedComment.Replace("\r\n", "\r"), buildStatus.Comment);
            Assert.AreEqual(new DateTime(2012, 1, 27, 0, 16, 2, 0), buildStatus.FinishedTime, HudsonBuildStatusTest.DateAsCode(buildStatus.FinishedTime.Value)); // timestamp+duration
            Assert.AreEqual("http://win7ci:8080/viewLog.html?buildId=35&buildTypeId=bt2", buildStatus.Url);
            Assert.AreEqual("35", buildStatus.BuildId);
        }
예제 #2
0
        public async Task TeamCityBuildMonitorTest()
        {
            var build = new TeamCityBuild
            {
                GuestUser   = true,
                Url         = "https://teamcity.jetbrains.com",
                BuildTypeId = "OpenSourceProjects_Kaxb_Build",
            };

            var request = HealthCheckRequest.Create(build);
            var handler = new TeamCityBuildStatus();

            await handler.Handle(request, CancellationToken.None);

            Assert.AreNotEqual(State.None, request.DataContext.State);
            Assert.AreNotEqual(State.Error, request.DataContext.State);
        }
        public void TeamCityFailureDueToCleanup()
        {
            var teamCityFailureDueToCleanup = TeamCityResources.TeamCityFailureDueToCleanup;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting
            {
                Name = "Name",
                Id   = "BuildDefinitionId"
            };
            var buildStatus = new TeamCityBuildStatus(buildDefinitionSetting, teamCityFailureDueToCleanup, null);

            Assert.AreEqual(BuildStatusEnum.Unknown, buildStatus.BuildStatusEnum);
            Assert.AreEqual("BuildDefinitionId", buildStatus.BuildDefinitionId);
            Assert.AreEqual("db_maintenance Database [GRAVIS1]", buildStatus.Name);
            Assert.AreEqual(null, buildStatus.RequestedBy);
            Assert.AreEqual(new DateTime(2012, 5, 29, 21, 0, 7, 0), buildStatus.StartedTime, HudsonBuildStatusTest.DateAsCode(buildStatus.StartedTime.Value));
            Assert.AreEqual(null, buildStatus.Comment);
            Assert.AreEqual(new DateTime(2012, 5, 29, 21, 0, 12, 0), buildStatus.FinishedTime, HudsonBuildStatusTest.DateAsCode(buildStatus.FinishedTime.Value)); // timestamp+duration
            Assert.AreEqual("http://teamcity.com/viewLog.html?buildId=32470&buildTypeId=bt231", buildStatus.Url);
            Assert.AreEqual("32470", buildStatus.BuildId);
        }
        public void TeamCityBuildStatus_Working_10_0_0_4()
        {
            var buildInfo  = TeamCityResources.TeamCity_10004_BuildInfo;
            var changeInfo = TeamCityResources.TeamCity_10004_changeInfo;
            BuildDefinitionSetting buildDefinitionSetting = new BuildDefinitionSetting
            {
                Name = "Name",
                Id   = "BuildDefinitionId"
            };
            var buildStatus = new TeamCityBuildStatus(buildDefinitionSetting, buildInfo, changeInfo);

            Assert.AreEqual(BuildStatusEnum.Working, buildStatus.BuildStatusEnum);
            Assert.AreEqual("BuildDefinitionId", buildStatus.BuildDefinitionId);
            Assert.AreEqual("Tests", buildStatus.Name);
            Assert.AreEqual("*****@*****.**", buildStatus.RequestedBy);
            Assert.AreEqual(new DateTime(2017, 1, 1, 12, 00, 00, 0), buildStatus.StartedTime, HudsonBuildStatusTest.DateAsCode(buildStatus.StartedTime.Value));
            string expectedComment = "someonebroke the build and I am very sad";

            Assert.AreEqual(expectedComment.Replace("\r\n", "\r"), buildStatus.Comment);
            Assert.AreEqual(new DateTime(2017, 1, 1, 12, 00, 00, 0), buildStatus.FinishedTime, HudsonBuildStatusTest.DateAsCode(buildStatus.FinishedTime.Value)); // timestamp+duration
            Assert.AreEqual("http://teamcity/viewLog.html?buildId=12345&buildTypeId=Test_Build_ID", buildStatus.Url);
            Assert.AreEqual("12345", buildStatus.BuildId);
        }
예제 #5
0
        public async Task QueueBuildAsync(CancellationToken cancellationToken, bool logProgressToExecutionLog)
        {
            this.Logger.LogInformation($"Queueing build in TeamCity...");

            if (this.BuildConfigurationName != null && this.ProjectName != null && this.BuildConfigurationId == null)
            {
                await SetBuildConfigurationIdFromName().ConfigureAwait(false);
            }

            using (var client = new TeamCityWebClient(this.ConnectionInfo))
            {
                this.Logger.LogDebug("Triggering build configuration {0}...", this.BuildConfigurationId);
                if (this.BranchName != null)
                {
                    this.Logger.LogDebug("Using branch: " + this.BranchName);
                }

                var xdoc = new XDocument(
                    new XElement("build",
                                 new XAttribute("branchName", this.BranchName ?? ""),
                                 new XElement("buildType", new XAttribute("id", this.BuildConfigurationId))
                                 )
                    );
                string response = await client.UploadStringTaskAsync("app/rest/buildQueue", xdoc.ToString(SaveOptions.DisableFormatting)).ConfigureAwait(false);

                var status = new TeamCityBuildStatus(response);

                this.Logger.LogInformation("Build of {0} was triggered successfully.", this.BuildConfigurationId);

                if (!this.WaitForCompletion)
                {
                    return;
                }

                this.Logger.LogInformation("Waiting for build to complete...");

                while (!status.Finished)
                {
                    string getBuildStatusResponse = await client.DownloadStringTaskAsync(status.Href).ConfigureAwait(false);

                    status = new TeamCityBuildStatus(getBuildStatusResponse);

                    this.progressPercent = status.PercentageComplete;
                    this.progressMessage = $"Building {status.ProjectName} Build #{status.Number} ({status.PercentageComplete}% Complete)";

                    if (logProgressToExecutionLog)
                    {
                        this.Logger.LogInformation(this.progressMessage);
                    }

                    await Task.Delay(2000, cancellationToken).ConfigureAwait(false);

                    cancellationToken.ThrowIfCancellationRequested();
                }

                if (status.Success)
                {
                    this.Logger.LogInformation($"{status.ProjectName} build #{status.Number} successful. TeamCity reports: {status.StatusText}");
                }
                else
                {
                    this.Logger.LogError($"{status.ProjectName} build #{status.Number} failed or encountered an error. TeamCity reports: {status.StatusText}");
                }
            }
        }
예제 #6
0
        protected override void Execute()
        {
            string triggerUrl = string.Format("action.html?add2Queue={0}{1}", this.BuildConfigurationId, this.AdditionalParameters);

            using (var client = CreateClient())
            {
                LogDebug("Triggering build of configuration {0} at {1}", this.BuildConfigurationId, GetExtensionConfigurer().BaseUrl + triggerUrl);
                client.DownloadString(triggerUrl);

                LogInformation("Build of {0} was triggered successfully.", this.BuildConfigurationId);

                if (!this.WaitForCompletion)
                    return;

                Thread.Sleep(3000); // give TeamCity some time to create the build

                string getLatestBuildUrl = string.Format("app/rest/builds?locator=buildType:{0},count:1,running:true", this.BuildConfigurationId);
                string getLatestBuildResponse = client.DownloadString(getLatestBuildUrl);
                string latestBuildId = ParseBuildId(getLatestBuildResponse);
                if (latestBuildId == null)
                {
                    LogError("BuildMaster has triggered a build in TeamCity, but TeamCity indicates that there are no builds running at this time, therefore BuildMaster cannot wait until the build completes.");
                    return;
                }

                string getBuildStatusUrl = string.Format("app/rest/builds/id:{0}", latestBuildId);

                TeamCityBuildStatus buildStatus;
                do
                {
                    string getBuildStatusResponse = client.DownloadString(getBuildStatusUrl);
                    buildStatus = new TeamCityBuildStatus(getBuildStatusResponse);

                    LogInformation("Building {0} Build #{1} ({2}% Complete)", buildStatus.ProjectName, buildStatus.BuildNumber, buildStatus.PercentComplete);

                    Thread.Sleep(4000);

                } while(buildStatus.IsRunning);

                if (buildStatus.Status == TeamCityBuildStatus.BuildStatuses.Success)
                {
                    LogInformation("{0} build #{1} successful. TeamCity reports: {2}", buildStatus.ProjectName, buildStatus.BuildNumber, buildStatus.StatusText);
                }
                else if (buildStatus.Status == TeamCityBuildStatus.BuildStatuses.Failure)
                {
                    LogError("{0} build #{1} failed. TeamCity reports: {2}", buildStatus.ProjectName, buildStatus.BuildNumber, buildStatus.StatusText);
                }
                else
                {
                    LogError("{0} build #{1} encountered an error. TeamCity reports: {2}", buildStatus.ProjectName, buildStatus.BuildNumber, buildStatus.StatusText);
                }
            }
        }
 public void SetUp()
 {
     _client = new Client("localhost:81");
     _client.Connect("admin", "qwerty");
 }