Skip to content

Commit

Permalink
[PublishTestResultsV2] Add option to fail task if no test result file…
Browse files Browse the repository at this point in the history
…s are found (#18931)

* added fail condition if no test file found

* Update task.json

* Update publishtestresults.ts
  • Loading branch information
triptijain2112 authored Sep 11, 2023
1 parent d10d637 commit b19956f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"loc.input.help.mergeTestResults": "A test run is created for each results file. Check this option to merge results into a single test run. To optimize for better performance, results will be merged into a single run if there are more than 100 result files, irrespective of this option.",
"loc.input.label.failTaskOnFailedTests": "Fail if there are test failures",
"loc.input.help.failTaskOnFailedTests": "Fail the task if there are any test failures. Check this option to fail the task if test failures are detected in the result files.",
"loc.input.label.failTaskOnMissingResultsFile": "ms-resource:loc.input.label.failTaskOnMissingResultsFile",
"loc.input.help.failTaskOnMissingResultsFile": "ms-resource:loc.input.help.failTaskOnMissingResultsFile",
"loc.input.label.testRunTitle": "Test run title",
"loc.input.help.testRunTitle": "Provide a name for the Test Run.",
"loc.input.label.platform": "Build Platform",
Expand Down
9 changes: 8 additions & 1 deletion Tasks/PublishTestResultsV2/publishtestresults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async function run() {
const testRunTitle = tl.getInput('testRunTitle');
const publishRunAttachments = tl.getInput('publishRunAttachments');
const failTaskOnFailedTests = tl.getInput('failTaskOnFailedTests');
const failTaskOnMissingResultsFile: boolean = tl.getBoolInput('failTaskOnMissingResultsFile');
let searchFolder = tl.getInput('searchFolder');

tl.debug('testRunner: ' + testRunner);
Expand All @@ -82,6 +83,7 @@ async function run() {
tl.debug('testRunTitle: ' + testRunTitle);
tl.debug('publishRunAttachments: ' + publishRunAttachments);
tl.debug('failTaskOnFailedTests: ' + failTaskOnFailedTests);
tl.debug('failTaskOnMissingResultsFile: ' + failTaskOnMissingResultsFile);

if (isNullOrWhitespace(searchFolder)) {
searchFolder = tl.getVariable('System.DefaultWorkingDirectory');
Expand Down Expand Up @@ -111,6 +113,7 @@ async function run() {
ci.addToConsolidatedCi('config', config);
ci.addToConsolidatedCi('platform', platform);
ci.addToConsolidatedCi('testResultsFilesCount', testResultsFilesCount);
ci.addToConsolidatedCi('failTaskOnMissingResultsFile', failTaskOnMissingResultsFile);

const dotnetVersion = getDotNetVersion();
ci.addToConsolidatedCi('dotnetVersion', dotnetVersion);
Expand All @@ -121,7 +124,11 @@ async function run() {
}

if (testResultsFilesCount === 0) {
tl.warning('No test result files matching ' + testResultsFiles + ' were found.');
if (failTaskOnMissingResultsFile) {
tl.setResult(tl.TaskResult.Failed, tl.loc('NoMatchingFilesFound', testResultsFiles));
} else {
tl.warning(tl.loc('NoMatchingFilesFound', testResultsFiles));
}
ci.addToConsolidatedCi('noResultsFileFound', true);
} else {
const osType = tl.osType();
Expand Down
14 changes: 11 additions & 3 deletions Tasks/PublishTestResultsV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 216,
"Patch": 2
"Minor": 228,
"Patch": 0
},
"demands": [],
"releaseNotes": "<ul><li>NUnit3 support</li><li>Support for Minimatch files pattern</li></ul>",
Expand Down Expand Up @@ -81,6 +81,14 @@
"required": false,
"helpMarkDown": "Fail the task if there are any test failures. Check this option to fail the task if test failures are detected in the result files."
},
{
"name": "failTaskOnMissingResultsFile",
"type": "boolean",
"label": "ms-resource:loc.input.label.failTaskOnMissingResultsFile",
"defaultValue": false,
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnMissingResultsFile"
},
{
"name": "testRunTitle",
"type": "string",
Expand Down Expand Up @@ -139,4 +147,4 @@
"ErrorTestResultsPublisher": "Error while executing TestResultsPublisher: %s.",
"ErrorFailTaskOnFailedTests": "There are one or more test failures detected in result files. Detailed summary of published test results can be viewed in the Tests tab."
}
}
}
12 changes: 10 additions & 2 deletions Tasks/PublishTestResultsV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 216,
"Patch": 2
"Minor": 228,
"Patch": 0
},
"demands": [],
"releaseNotes": "ms-resource:loc.releaseNotes",
Expand Down Expand Up @@ -81,6 +81,14 @@
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailedTests"
},
{
"name": "failTaskOnMissingResultsFile",
"type": "boolean",
"label": "ms-resource:loc.input.label.failTaskOnMissingResultsFile",
"defaultValue": false,
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnMissingResultsFile"
},
{
"name": "testRunTitle",
"type": "string",
Expand Down

0 comments on commit b19956f

Please sign in to comment.