コード例 #1
0
 private async Task PopulateCounters(BuildResultEntity result)
 {
     await _buildCounterUtil.UpdateAsync(x =>
     {
         var succeeded = result.ClassificationKind == ClassificationKind.Succeeded;
         if (JobUtil.IsPullRequestJobName(result.JobName))
         {
             if (succeeded)
             {
                 x.PullRequestSucceededCount++;
             }
             else
             {
                 x.PullRequestFailedCount++;
             }
         }
         else
         {
             if (succeeded)
             {
                 x.CommitSucceededCount++;
             }
             else
             {
                 x.CommitFailedCount++;
             }
         }
     });
 }
コード例 #2
0
        /// <summary>
        /// Is this build alreadiy fully populated.
        /// </summary>
        public async Task <bool> IsPopulated(BuildId buildId, CancellationToken cancellationToken = default(CancellationToken))
        {
            var key    = BuildResultEntity.GetExactEntityKey(buildId);
            var entity = await AzureUtil.QueryAsync <DynamicTableEntity>(_buildResultExactTable, key, cancellationToken);

            return(entity != null);
        }
コード例 #3
0
        public BuildResultEntity CopyExact()
        {
            var entity = new BuildResultEntity(this);

            entity.SetEntityKey(GetExactEntityKey(BuildId));
            return(entity);
        }
コード例 #4
0
        public BuildResultEntity CopyDate()
        {
            var entity = new BuildResultEntity(this);

            entity.SetEntityKey(GetDateEntityKey(BuildDateTimeOffset, BuildId));
            return(entity);
        }
コード例 #5
0
 public BuildResultEntity(BuildResultEntity other) : this(
         buildId : other.BoundBuildId,
         buildDateTime : other.BuildDateTimeOffset,
         duration : other.Duration,
         jobKind : other.JobKind,
         machineName : other.MachineName,
         classification : other.Classification,
         prInfo : other.PullRequestInfo)
 {
 }
コード例 #6
0
 public void PullRequestInfo()
 {
     var buildId = Create("example.com", 42, JobId.ParseName("hello"));
     var buildDate = DateTimeOffset.UtcNow;
     var prInfo = new PullRequestInfo("bob", "dog", 42, "cat", "tree");
     var entity = new BuildResultEntity(
         buildId,
         buildDate,
         TimeSpan.FromSeconds(1),
         "kind",
         "test",
         BuildResultClassification.Succeeded,
         prInfo: prInfo);
     Assert.True(entity.HasPullRequestInfo);
     Assert.Equal(entity.PullRequestInfo.Author, prInfo.Author);
     Assert.Equal(entity.PullRequestInfo.AuthorEmail, prInfo.AuthorEmail);
     Assert.Equal(entity.PullRequestInfo.Id, prInfo.Id);
     Assert.Equal(entity.PullRequestInfo.PullUrl, prInfo.PullUrl);
     Assert.Equal(entity.PullRequestSha1, prInfo.Sha1);
 }
コード例 #7
0
        public async Task PopulateBuildMissing(BoundBuildId buildId)
        {
            // The bulid is now deemed to be missing.  Finish it off.
            var result = new BuildResultEntity(
                buildId,
                DateTimeOffset.UtcNow,
                TimeSpan.MinValue,
                JobKind.Normal,
                "",
                BuildResultClassification.Infrastructure,
                prInfo: null);

            // Deliberately using Insert here vs. InsertOrReplace.  This is the worst possible outcome for this
            // type so let anyone else win
            await _buildResultDateTable.ExecuteAsync(TableOperation.Insert(result.CopyDate()));

            await _buildResultDateTable.ExecuteAsync(TableOperation.Insert(result.CopyExact()));

            await PopulateCounters(result);
        }
コード例 #8
0
 public void Properties()
 {
     var buildId = Create("example.com", 42, JobId.ParseName("hello"));
     var buildDate = DateTimeOffset.UtcNow;
     var entity = new BuildResultEntity(
         buildId,
         buildDate,
         TimeSpan.FromSeconds(1),
         "kind",
         "test",
         BuildResultClassification.Succeeded,
         prInfo: null);
     Assert.Equal(BuildResultClassification.Succeeded.Kind, entity.Classification.Kind);
     Assert.Equal(BuildResultClassification.Succeeded.Name, entity.Classification.Name);
     Assert.Equal(buildId, entity.BoundBuildId);
     Assert.Equal(buildId.Number, entity.BuildNumber);
     Assert.Equal(buildId.JobId, entity.JobId);
     Assert.Equal(buildDate, entity.BuildDateTimeOffset);
     Assert.Equal("test", entity.MachineName);
     Assert.False(entity.HasPullRequestInfo);
     Assert.Null(entity.PullRequestInfo);
 }
コード例 #9
0
        public void MissingHostName()
        {
            var jobId = JobId.ParseName("test");
            var entity = new BuildResultEntity()
            {
                BuildNumber = 42,
                JobName = jobId.Name
            };

            var buildId = entity.BoundBuildId;
            Assert.Equal(LegacyUtil.DefaultHost, buildId.Host);
            Assert.Equal(jobId, buildId.JobId);
            Assert.Equal(42, buildId.Number);
        }
コード例 #10
0
 public void ViewNameOther()
 {
     var buildId = Create("example.com", 42, JobId.ParseName("house/test"));
     var entity = new BuildResultEntity(buildId, DateTimeOffset.UtcNow, TimeSpan.FromSeconds(1), "kind", "test", BuildResultClassification.Succeeded, null);
     Assert.Equal("house", entity.ViewName);
 }
コード例 #11
0
ファイル: BuildResultEntity.cs プロジェクト: jaredpar/jenkins
 public BuildResultEntity CopyExact()
 {
     var entity = new BuildResultEntity(this);
     entity.SetEntityKey(GetExactEntityKey(BuildId));
     return entity;
 }
コード例 #12
0
        /// <summary>
        /// Update the table storage to contain the result of the specified build.
        /// </summary>
        private async Task<PopulateData> GetPopulateDataCore(BoundBuildId id)
        {
            var buildInfo = await _client.GetBuildInfoAsync(id.BuildId);
            var jobKind = await _client.GetJobKindAsync(id.JobId);

            PullRequestInfo prInfo = null;
            if (JobUtil.IsPullRequestJobName(id.JobId.Name))
            {
                try
                {
                    prInfo = await _client.GetPullRequestInfoAsync(id.BuildId);
                }
                catch (Exception ex)
                {
                    // TODO: Flow builds don't have the PR directly in the triggered jobs.  Have to walk
                    // back up to the parent job.  For now swallow this error so we don't trigger false
                    // positives in the error detection.
                    _textWriter.WriteLine($"Error pulling PR info for {id}: {ex.Message}");
                }
            }

            BuildResultClassification classification;
            switch (buildInfo.State)
            {
                case BuildState.Succeeded:
                    classification = BuildResultClassification.Succeeded;
                    break;
                case BuildState.Aborted:
                    classification = BuildResultClassification.Aborted;
                    break;
                case BuildState.Failed:
                    classification = await PopulateFailedBuildResult(buildInfo, jobKind, prInfo);
                    break;
                case BuildState.Running:
                    classification = BuildResultClassification.Unknown;
                    break;
                default:
                    throw new Exception($"Invalid enum: {buildInfo.State} for {id.JobName} - {id.Number}");
            }

            var resultEntity = new BuildResultEntity(
                id,
                buildInfo.Date,
                buildInfo.Duration,
                jobKind: jobKind,
                machineName: buildInfo.MachineName,
                classification: classification,
                prInfo: prInfo);

            var failures = classification.Kind == ClassificationKind.TestFailure
                ? await GetUnitTestFailures(buildInfo, jobKind, prInfo)
                : new List<BuildFailureEntity>();

            return new PopulateData(resultEntity, failures);
        }
コード例 #13
0
ファイル: BuildResultEntity.cs プロジェクト: jaredpar/jenkins
        public BuildResultEntity(BuildResultEntity other) : this(
            buildId: other.BoundBuildId,
            buildDateTime: other.BuildDateTimeOffset,
            duration: other.Duration,
            jobKind: other.JobKind,
            machineName: other.MachineName,
            classification: other.Classification,
            prInfo: other.PullRequestInfo)
        {

        }
コード例 #14
0
        public async Task PopulateBuildMissing(BoundBuildId buildId)
        {
            // The bulid is now deemed to be missing.  Finish it off.
            var result = new BuildResultEntity(
                buildId,
                DateTimeOffset.UtcNow,
                TimeSpan.MinValue,
                JobKind.Normal,
                "",
                BuildResultClassification.Infrastructure,
                prInfo: null);

            // Deliberately using Insert here vs. InsertOrReplace.  This is the worst possible outcome for this
            // type so let anyone else win
            await _buildResultDateTable.ExecuteAsync(TableOperation.Insert(result.CopyDate()));
            await _buildResultDateTable.ExecuteAsync(TableOperation.Insert(result.CopyExact()));
            await PopulateCounters(result);
        }
コード例 #15
0
        /// <summary>
        /// Update the table storage to contain the result of the specified build.
        /// </summary>
        private async Task <PopulateData> GetPopulateDataCore(BoundBuildId id)
        {
            var buildInfo = await _client.GetBuildInfoAsync(id.BuildId);

            var jobKind = await _client.GetJobKindAsync(id.JobId);

            PullRequestInfo prInfo = null;

            if (JobUtil.IsPullRequestJobName(id.JobId.Name))
            {
                try
                {
                    prInfo = await _client.GetPullRequestInfoAsync(id.BuildId);
                }
                catch (Exception ex)
                {
                    // TODO: Flow builds don't have the PR directly in the triggered jobs.  Have to walk
                    // back up to the parent job.  For now swallow this error so we don't trigger false
                    // positives in the error detection.
                    _textWriter.WriteLine($"Error pulling PR info for {id}: {ex.Message}");
                }
            }

            BuildResultClassification classification;

            switch (buildInfo.State)
            {
            case BuildState.Succeeded:
                classification = BuildResultClassification.Succeeded;
                break;

            case BuildState.Aborted:
                classification = BuildResultClassification.Aborted;
                break;

            case BuildState.Failed:
                classification = await PopulateFailedBuildResult(buildInfo, jobKind, prInfo);

                break;

            case BuildState.Running:
                classification = BuildResultClassification.Unknown;
                break;

            default:
                throw new Exception($"Invalid enum: {buildInfo.State} for {id.JobName} - {id.Number}");
            }

            var resultEntity = new BuildResultEntity(
                id,
                buildInfo.Date,
                buildInfo.Duration,
                jobKind: jobKind,
                machineName: buildInfo.MachineName,
                classification: classification,
                prInfo: prInfo);

            var failures = classification.Kind == ClassificationKind.TestFailure
                ? await GetUnitTestFailures(buildInfo, jobKind, prInfo)
                : new List <BuildFailureEntity>();

            return(new PopulateData(resultEntity, failures));
        }
コード例 #16
0
 private async Task PopulateCounters(BuildResultEntity result)
 {
     await _buildCounterUtil.UpdateAsync(x =>
     {
         var succeeded = result.ClassificationKind == ClassificationKind.Succeeded;
         if (JobUtil.IsPullRequestJobName(result.JobName))
         {
             if (succeeded)
             {
                 x.PullRequestSucceededCount++;
             }
             else
             {
                 x.PullRequestFailedCount++;
             }
         }
         else
         {
             if (succeeded)
             {
                 x.CommitSucceededCount++;
             }
             else
             {
                 x.CommitFailedCount++;
             }
         }
     });
 }
コード例 #17
0
 internal PopulateData(BuildResultEntity result, List <BuildFailureEntity> failures)
 {
     Result   = result;
     Failures = failures;
 }
コード例 #18
0
 internal PopulateData(BuildResultEntity result, List<BuildFailureEntity> failures)
 {
     Result = result;
     Failures = failures;
 }
コード例 #19
0
ファイル: BuildResultEntity.cs プロジェクト: jaredpar/jenkins
 public BuildResultEntity CopyDate()
 {
     var entity = new BuildResultEntity(this);
     entity.SetEntityKey(GetDateEntityKey(BuildDateTimeOffset, BuildId));
     return entity;
 }