Skip to content

Commit ee56363

Browse files
eswarnathprudhivieswarnathpv-mazayt
authored
Provide option for user to fail PTR if no results are uploaded (#19347)
* Added files required for the change * changed the versoin in task.loc.kson * Updated the version * updated the version * updated generated files * resolved build error * changed task.loc.json * changed task.loc.json * Update task.locl.json * resolved test failures --------- Co-authored-by: Eswarnath Prudhivi (from Dev Box) <[email protected]> Co-authored-by: v-mazayt <[email protected]>
1 parent cfee22e commit ee56363

File tree

17 files changed

+106
-32
lines changed

17 files changed

+106
-32
lines changed

Tasks/PublishTestResultsV2/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"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.",
1616
"loc.input.label.failTaskOnFailedTests": "Fail if there are test failures",
1717
"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.",
18+
"loc.input.label.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results",
19+
"loc.input.help.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results. Check this option to fail the task if publishing test results is failed partially.",
1820
"loc.input.label.failTaskOnMissingResultsFile": "Fail if no result files are found",
1921
"loc.input.help.failTaskOnMissingResultsFile": "Fail the task if no result files are found.",
2022
"loc.input.label.testRunTitle": "Test run title",

Tasks/PublishTestResultsV2/Tests/Constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export const failTaskOnFailedTests = 'failTaskOnFailedTests';
1313
export const proxyUrl = 'agent.proxyurl';
1414
export const proxyUserName = 'agent.proxyusername';
1515
export const proxyPassword = 'agent.proxypassword';
16-
export const proxyByPassHosts = 'agent.proxybypasslist';
16+
export const proxyByPassHosts = 'agent.proxybypasslist';
17+
export const failTaskOnFailureToPublishResults = 'failTaskOnFailureToPublishResults';

Tasks/PublishTestResultsV2/Tests/L0.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('PublishTestResults Suite', function() {
2929
delete process.env[constants.listPackagesReturnCode];
3030
delete process.env[constants.osType];
3131
delete process.env[constants.failTaskOnFailedTests];
32+
delete process.env[constants.failTaskOnFailureToPublishResults];
3233

3334
done();
3435
});
@@ -60,6 +61,7 @@ describe('PublishTestResults Suite', function() {
6061
process.env[constants.proxyUserName] = "1";
6162
process.env[constants.proxyPassword] = "1";
6263
process.env[constants.proxyByPassHosts] = undefined;
64+
process.env[constants.failTaskOnFailureToPublishResults] = 'false';
6365

6466
// Start the run
6567
tr.run();
@@ -96,6 +98,7 @@ describe('PublishTestResults Suite', function() {
9698
process.env[constants.proxyUserName] = "1";
9799
process.env[constants.proxyPassword] = "1";
98100
process.env[constants.proxyByPassHosts] = undefined;
101+
process.env[constants.failTaskOnFailureToPublishResults] = 'false';
99102

100103
// Start the run
101104
tr.run();
@@ -132,6 +135,7 @@ describe('PublishTestResults Suite', function() {
132135
process.env[constants.proxyUserName] = "1";
133136
process.env[constants.proxyPassword] = "1";
134137
process.env[constants.proxyByPassHosts] = undefined;
138+
process.env[constants.failTaskOnFailureToPublishResults] = 'false';
135139

136140
// Start the run
137141
tr.run();
@@ -142,7 +146,7 @@ describe('PublishTestResults Suite', function() {
142146
assert.equal(tr.invokedToolCount, 1, `invoked tool count should be 1`);
143147
assert(tr.stdOutContained(`TestResultsPublisher.exe`),
144148
`Should have called TestResultsPublisher.exe first`);
145-
assert(tr.stdOutContained(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]`),
149+
assert(tr.stdOutContained(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;failTaskOnFailureToPublishResults=false;testRunSystem=VSTS - PTR;]`),
146150
`Should have published results through Command when feature flag is off`);
147151

148152
done();
@@ -172,6 +176,7 @@ describe('PublishTestResults Suite', function() {
172176
process.env[constants.proxyUserName] = "1";
173177
process.env[constants.proxyPassword] = "1";
174178
process.env[constants.proxyByPassHosts] = undefined;
179+
process.env[constants.failTaskOnFailureToPublishResults] = 'false';
175180

176181
// Start the run
177182
tr.run();
@@ -182,7 +187,7 @@ describe('PublishTestResults Suite', function() {
182187
assert.equal(tr.invokedToolCount, 1, `invoked tool count should be 1`);
183188
assert(tr.stdOutContained(`TestResultsPublisher.exe`),
184189
`Should have called TestResultsPublisher.exe first`);
185-
assert(tr.stdout.indexOf(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;testRunSystem=VSTS - PTR;]`) < 0,
190+
assert(tr.stdout.indexOf(`vso[results.publish type=VSTest;mergeResults=false;publishRunAttachments=false;resultFiles=n-files0.xml;failTaskOnFailedTests=false;failTaskOnFailureToPublishResults=false;testRunSystem=VSTS - PTR;]`) < 0,
186191
`Command should not have been called when exe returns with exit code suggesting feature flag is on`);
187192

188193
done();

Tasks/PublishTestResultsV2/Tests/TestSetup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tr.setInput('testRunTitle', process.env[constants.testRunTitle]);
1818
tr.setInput('publishRunAttachments', process.env[constants.publishRunAttachments]);
1919
tr.setInput('searchFolder', process.env[constants.searchFolder]);
2020
tr.setInput('failTaskOnFailedTests', process.env[constants.failTaskOnFailedTests]);
21+
tr.setInput('failTaskOnFailureToPublishResults', process.env[constants.failTaskOnFailureToPublishResults]);
2122

2223
const PublishExeToolPath = path.join(__dirname, '../modules', 'TestResultsPublisher.exe');
2324
const newUuid = "1e1faf9e-d9e5-4054-b351-398ac75b62f5";

Tasks/PublishTestResultsV2/publishtestresults.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function isNullOrWhitespace(input: any) {
1616
return input.replace(/\s/g, '').length < 1;
1717
}
1818

19-
function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, platform, config, runTitle, publishRunAttachments, testRunSystem) {
19+
function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, platform, config, runTitle, publishRunAttachments, testRunSystem , failTaskOnFailureToPublishResults) {
2020
var properties = <{ [key: string]: string }>{};
2121
properties['type'] = testRunner;
2222

@@ -41,6 +41,9 @@ function publish(testRunner, resultFiles, mergeResults, failTaskOnFailedTests, p
4141
if(failTaskOnFailedTests){
4242
properties['failTaskOnFailedTests'] = failTaskOnFailedTests;
4343
}
44+
if(failTaskOnFailureToPublishResults){
45+
properties['failTaskOnFailureToPublishResults'] = failTaskOnFailureToPublishResults;
46+
}
4447
properties['testRunSystem'] = testRunSystem;
4548

4649
tl.command('results.publish', properties, '');
@@ -73,6 +76,7 @@ async function run() {
7376
const publishRunAttachments = tl.getInput('publishRunAttachments');
7477
const failTaskOnFailedTests = tl.getInput('failTaskOnFailedTests');
7578
const failTaskOnMissingResultsFile: boolean = tl.getBoolInput('failTaskOnMissingResultsFile');
79+
const failTaskOnFailureToPublishResults = tl.getInput('failTaskOnFailureToPublishResults');
7680
let searchFolder = tl.getInput('searchFolder');
7781

7882
tl.debug('testRunner: ' + testRunner);
@@ -84,6 +88,7 @@ async function run() {
8488
tl.debug('publishRunAttachments: ' + publishRunAttachments);
8589
tl.debug('failTaskOnFailedTests: ' + failTaskOnFailedTests);
8690
tl.debug('failTaskOnMissingResultsFile: ' + failTaskOnMissingResultsFile);
91+
tl.debug('failTaskOnFailureToPublishResults: ' + failTaskOnFailureToPublishResults);
8792

8893
if (isNullOrWhitespace(searchFolder)) {
8994
searchFolder = tl.getVariable('System.DefaultWorkingDirectory');
@@ -114,6 +119,7 @@ async function run() {
114119
ci.addToConsolidatedCi('platform', platform);
115120
ci.addToConsolidatedCi('testResultsFilesCount', testResultsFilesCount);
116121
ci.addToConsolidatedCi('failTaskOnMissingResultsFile', failTaskOnMissingResultsFile);
122+
ci.addToConsolidatedCi('failTaskOnFailureToPublishResults', failTaskOnFailureToPublishResults);
117123

118124
const dotnetVersion = getDotNetVersion();
119125
ci.addToConsolidatedCi('dotnetVersion', dotnetVersion);
@@ -146,7 +152,8 @@ async function run() {
146152
testRunTitle,
147153
publishRunAttachments,
148154
testRunner,
149-
TESTRUN_SYSTEM);
155+
TESTRUN_SYSTEM,
156+
failTaskOnFailureToPublishResults);
150157
const exitCode = await testResultsPublisher.publishResultsThroughExe();
151158
tl.debug("Exit code of TestResultsPublisher: " + exitCode);
152159

@@ -159,7 +166,8 @@ async function run() {
159166
config,
160167
testRunTitle,
161168
publishRunAttachments,
162-
TESTRUN_SYSTEM);
169+
TESTRUN_SYSTEM,
170+
failTaskOnFailureToPublishResults);
163171
} else if (exitCode === 40000) {
164172
// The exe returns with exit code: 40000 if there are test failures found and failTaskOnFailedTests is true
165173
ci.addToConsolidatedCi('failedTestsInRun', true);
@@ -179,7 +187,8 @@ async function run() {
179187
config,
180188
testRunTitle,
181189
publishRunAttachments,
182-
TESTRUN_SYSTEM);
190+
TESTRUN_SYSTEM,
191+
failTaskOnFailureToPublishResults);
183192
}
184193
}
185194
tl.setResult(tl.TaskResult.Succeeded, '');

Tasks/PublishTestResultsV2/publishtestresultstool.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ let uuid = require('uuid');
99

1010
export class TestResultsPublisher {
1111
constructor(matchingTestResultsFiles: string[], mergeResults: string, failTaskOnFailedTests: string, platform: string, config: string,
12-
testRunTitle: string, publishRunAttachments: string, testRunner: string, testRunSystem: string) {
12+
testRunTitle: string, publishRunAttachments: string, testRunner: string, testRunSystem: string
13+
,failTaskOnFailureToPublishResults: string) {
1314

1415
this.matchingTestResultsFiles = matchingTestResultsFiles.slice(0);
1516
this.mergeResults = mergeResults;
@@ -20,6 +21,7 @@ export class TestResultsPublisher {
2021
this.publishRunAttachments = publishRunAttachments;
2122
this.testRunner = testRunner;
2223
this.testRunSystem = testRunSystem;
24+
this.failTaskOnFailureToPublishResults = failTaskOnFailureToPublishResults;
2325
}
2426

2527
public async publishResultsThroughExe(): Promise<number> {
@@ -120,7 +122,7 @@ export class TestResultsPublisher {
120122
envVars = this.addToProcessEnvVars(envVars, 'jobattempt', tl.getVariable('System.JobAttempt'));
121123
envVars = this.addToProcessEnvVars(envVars, 'jobidentifier', tl.getVariable('System.JobIdentifier'));
122124
envVars = this.addToProcessEnvVars(envVars, 'agenttempdirectory', tl.getVariable('Agent.TempDirectory'));
123-
125+
envVars = this.addToProcessEnvVars(envVars, 'failtaskonfailuretopublishresults', this.failTaskOnFailureToPublishResults);
124126
// Setting proxy details
125127
envVars = this.addToProcessEnvVars(envVars, "proxyurl", tl.getVariable('agent.proxyurl'));
126128
envVars = this.addToProcessEnvVars(envVars, "proxyusername", tl.getVariable('agent.proxyusername'));
@@ -151,4 +153,5 @@ export class TestResultsPublisher {
151153
private publishRunAttachments: string;
152154
private testRunner: string;
153155
private testRunSystem: string;
156+
private failTaskOnFailureToPublishResults: string;
154157
}

Tasks/PublishTestResultsV2/task.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 2,
16-
"Minor": 231,
17-
"Patch": 1
16+
"Minor": 232,
17+
"Patch": 0
1818
},
1919
"demands": [],
2020
"releaseNotes": "<ul><li>NUnit3 support</li><li>Support for Minimatch files pattern</li></ul>",
@@ -81,6 +81,14 @@
8181
"required": false,
8282
"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."
8383
},
84+
{
85+
"name": "failTaskOnFailureToPublishResults",
86+
"type": "boolean",
87+
"label": "Fail if there is failure in publishing test results",
88+
"defaultValue": false,
89+
"required": false,
90+
"helpMarkDown": "Fail if there is failure in publishing test results. Check this option to fail the task if publishing test results is failed partially."
91+
},
8492
{
8593
"name": "failTaskOnMissingResultsFile",
8694
"type": "boolean",

Tasks/PublishTestResultsV2/task.loc.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"author": "Microsoft Corporation",
1414
"version": {
1515
"Major": 2,
16-
"Minor": 231,
17-
"Patch": 1
16+
"Minor": 232,
17+
"Patch": 0
1818
},
1919
"demands": [],
2020
"releaseNotes": "ms-resource:loc.releaseNotes",
@@ -81,6 +81,14 @@
8181
"required": false,
8282
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailedTests"
8383
},
84+
{
85+
"name": "failTaskOnFailureToPublishResults",
86+
"type": "boolean",
87+
"label": "ms-resource:loc.input.label.failTaskOnFailureToPublishResults",
88+
"defaultValue": false,
89+
"required": false,
90+
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailureToPublishResults"
91+
},
8492
{
8593
"name": "failTaskOnMissingResultsFile",
8694
"type": "boolean",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Default|2.231.1
2-
Node20_229_13|2.231.2
1+
Default|2.232.0
2+
Node20_229_13|2.232.1

_generated/PublishTestResultsV2_Node20/Strings/resources.resjson/en-US/resources.resjson

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"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.",
1616
"loc.input.label.failTaskOnFailedTests": "Fail if there are test failures",
1717
"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.",
18+
"loc.input.label.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results",
19+
"loc.input.help.failTaskOnFailureToPublishResults": "Fail if there is failure in publishing test results. Check this option to fail the task if publishing test results is failed partially.",
1820
"loc.input.label.failTaskOnMissingResultsFile": "Fail if no result files are found",
1921
"loc.input.help.failTaskOnMissingResultsFile": "Fail the task if no result files are found.",
2022
"loc.input.label.testRunTitle": "Test run title",

0 commit comments

Comments
 (0)