private void ProcessPublishTestResultsCommand(IExecutionContext context, Dictionary <string, string> eventProperties, string data) { ArgUtil.NotNull(context, nameof(context)); _executionContext = context; LoadPublishTestResultsInputs(eventProperties, data); string teamProject = context.Variables.System_TeamProject; string owner = context.Variables.Build_RequestedFor; string buildUri = context.Variables.Build_BuildUri; int buildId = context.Variables.Build_BuildId ?? 0; //Temporary fix to support publish in RM scenarios where there might not be a valid Build ID associated. //TODO: Make a cleaner fix after TCM User Story 401703 is completed. if (buildId == 0) { _platform = _configuration = null; } string releaseUri = null; string releaseEnvironmentUri = null; // Check to identify if we are in the Release management flow; if not, then release fields will be kept null while publishing to TCM if (!string.IsNullOrWhiteSpace(context.Variables.Release_ReleaseUri)) { releaseUri = context.Variables.Release_ReleaseUri; releaseEnvironmentUri = context.Variables.Release_ReleaseEnvironmentUri; } IResultReader resultReader = GetTestResultReader(_testRunner); TestRunContext runContext = new TestRunContext(owner, _platform, _configuration, buildId, buildUri, releaseUri, releaseEnvironmentUri); Client.VssConnection connection = WorkerUtilies.GetVssConnection(_executionContext); var publisher = HostContext.GetService <ITestRunPublisher>(); publisher.InitializePublisher(context, connection, teamProject, resultReader); var commandContext = HostContext.CreateService <IAsyncCommandContext>(); commandContext.InitializeCommandContext(context, StringUtil.Loc("PublishTestResults")); if (_mergeResults) { commandContext.Task = PublishAllTestResultsToSingleTestRunAsync(_testResultFiles, publisher, buildId, runContext, resultReader.Name, context.CancellationToken); } else { commandContext.Task = PublishToNewTestRunPerTestResultFileAsync(_testResultFiles, publisher, runContext, resultReader.Name, context.CancellationToken); } _executionContext.AsyncCommands.Add(commandContext); }
private void ProcessPublishCodeCoverageCommand(IExecutionContext context, Dictionary <string, string> eventProperties) { ArgUtil.NotNull(context, nameof(context)); _buildId = context.Variables.Build_BuildId ?? -1; if (!IsHostTypeBuild(context) || _buildId < 0) { //In case the publishing codecoverage is not applicable for current Host type we continue without publishing context.Warning(StringUtil.Loc("CodeCoveragePublishIsValidOnlyForBuild")); return; } LoadPublishCodeCoverageInputs(eventProperties); string project = context.Variables.System_TeamProject; long?containerId = context.Variables.Build_ContainerId; ArgUtil.NotNull(containerId, nameof(containerId)); Guid projectId = context.Variables.System_TeamProjectId ?? Guid.Empty; ArgUtil.NotEmpty(projectId, nameof(projectId)); //step 1: read code coverage summary var reader = GetCodeCoverageSummaryReader(_codeCoverageTool); context.Output(StringUtil.Loc("ReadingCodeCoverageSummary", _summaryFileLocation)); var coverageData = reader.GetCodeCoverageSummary(context, _summaryFileLocation); if (coverageData == null || coverageData.Count() == 0) { context.Warning(StringUtil.Loc("CodeCoverageDataIsNull")); } Client.VssConnection connection = WorkerUtilies.GetVssConnection(context); var codeCoveragePublisher = HostContext.GetService <ICodeCoveragePublisher>(); codeCoveragePublisher.InitializePublisher(_buildId, connection); var commandContext = HostContext.CreateService <IAsyncCommandContext>(); commandContext.InitializeCommandContext(context, StringUtil.Loc("PublishCodeCoverage")); commandContext.Task = PublishCodeCoverageAsync(context, commandContext, codeCoveragePublisher, coverageData, project, projectId, containerId.Value, context.CancellationToken); context.AsyncCommands.Add(commandContext); }