Skip to content

Commit

Permalink
Calling results.publishmetadatatoevidencestore agent command to publi…
Browse files Browse the repository at this point in the history
…sh metadata. (#11878)

* Calling results.publishmetadatatoevidencestore agent command to publish metadata.

* Updating the PTR package version.

* publishing every time the exe is used.

* Increasing the agent version, as our code didn't make it to the agent 2.162.0 release
  • Loading branch information
navin22 authored Dec 15, 2019
1 parent 3c78644 commit 3b68a25
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Tasks/PublishTestResultsV2/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"externals": {
"archivePackages": [
{
"url": "https://publishtestresults.blob.core.windows.net/publishtestresults/11023201/PublishTestResults.zip",
"url": "https://publishtestresults.blob.core.windows.net/publishtestresults/11040905/PublishTestResults.zip",
"dest": "./"
}
]
Expand Down
39 changes: 36 additions & 3 deletions Tasks/PublishTestResultsV2/publishtestresults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import * as semver from "semver"
import * as publishTestResultsTool from './publishtestresultstool';
import * as tl from 'azure-pipelines-task-lib/task';
import * as tr from 'azure-pipelines-task-lib/toolrunner';
Expand Down Expand Up @@ -147,12 +149,17 @@ async function run() {
testRunTitle,
publishRunAttachments,
TESTRUN_SYSTEM);
}
else if(exitCode == 40000){
} else if (exitCode === 40000) {
// The exe returns with exit code: 40000 if there are test failures found and failTaskOnFailedTests is true
ci.addToConsolidatedCi('failedTestsInRun', true);
tl.setResult(tl.TaskResult.Failed, tl.loc('ErrorFailTaskOnFailedTests'));
}

if (exitCode !== 20000) {
// Doing it only for test results published using TestResultPublisher tool.
// For other publishes, publishing to evidence store happens as part of results.publish command itself.
readAndPublishTestRunSummaryToEvidenceStore(testRunner);
}
} else {
publish(testRunner, matchingTestResultsFiles,
forceMerge ? true.toString() : mergeResults,
Expand All @@ -165,11 +172,37 @@ async function run() {
}
}
tl.setResult(tl.TaskResult.Succeeded, '');
} catch (err) {
} catch (err) {
tl.setResult(tl.TaskResult.Failed, err);
} finally {
ci.fireConsolidatedCi();
}
}

function readAndPublishTestRunSummaryToEvidenceStore(testRunner: string) {
try {
const agentVersion = tl.getVariable('Agent.Version');
if(semver.lt(agentVersion, "2.162.1")) {
throw "Required agent version greater than or equal to 2.162.0";
}

var tempPath = tl.getVariable('Agent.TempDirectory');
var testRunSummaryPath = path.join(tempPath, "PTR_TEST_RUNSUMMARY.json");

var testRunSummary = fs.readFileSync(testRunSummaryPath, 'utf-8');

var properties = <{ [key: string]: string }>{};

properties['name'] = "PublishTestResults";
properties['testrunner'] = testRunner;
properties['testrunsummary'] = testRunSummary;
properties['description'] = "Test Results published from Publish Test Results tool";

tl.command('results.publishtoevidencestore', properties, '');
} catch (error) {
tl.debug(`Unable to publish the test run summary to evidencestore, error details:${error}`);
}

}

run();
1 change: 1 addition & 0 deletions Tasks/PublishTestResultsV2/publishtestresultstool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class TestResultsPublisher {
envVars = this.addToProcessEnvVars(envVars, 'jobname', tl.getVariable('System.JobName'));
envVars = this.addToProcessEnvVars(envVars, 'jobattempt', tl.getVariable('System.JobAttempt'));
envVars = this.addToProcessEnvVars(envVars, 'jobidentifier', tl.getVariable('System.JobIdentifier'));
envVars = this.addToProcessEnvVars(envVars, 'agenttempdirectory', tl.getVariable('Agent.TempDirectory'));

// Setting proxy details
envVars = this.addToProcessEnvVars(envVars, "proxyurl", tl.getVariable('agent.proxyurl'));
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PublishTestResultsV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 162,
"Minor": 163,
"Patch": 0
},
"demands": [],
Expand Down
2 changes: 1 addition & 1 deletion Tasks/PublishTestResultsV2/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 2,
"Minor": 162,
"Minor": 163,
"Patch": 0
},
"demands": [],
Expand Down

0 comments on commit 3b68a25

Please sign in to comment.