Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failTaskOnFailedTests option - Azure Test Plan #20712

Merged
merged 10 commits into from
Dec 6, 2024
4 changes: 3 additions & 1 deletion Tasks/AzureTestPlanV0/Invokers/maveninvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export async function executeMavenTests(testsToBeExecuted: string[], pomFilePath
args.push(pomFilePath);
}

args.push('-Dmaven.test.failure.ignore=true');
KathanS marked this conversation as resolved.
Show resolved Hide resolved

tl.debug("Executing java maven tests with executable : " + executable);
tl.debug("Executing java maven tests with args :" + args);

let status = await execMavenBuild(args);

return status ?? 1;
}
}
4 changes: 2 additions & 2 deletions Tasks/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 248,
"Minor": 250,
"Patch": 0
},
"preview": true,
Expand Down Expand Up @@ -123,7 +123,7 @@
"name": "failTaskOnFailedTests",
"type": "boolean",
"label": "Fail if there are test failures",
"defaultValue": "false",
"defaultValue": "true",
"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."
},
Expand Down
4 changes: 2 additions & 2 deletions Tasks/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 248,
"Minor": 250,
"Patch": 0
},
"preview": true,
Expand Down Expand Up @@ -123,7 +123,7 @@
"name": "failTaskOnFailedTests",
"type": "boolean",
"label": "ms-resource:loc.input.label.failTaskOnFailedTests",
"defaultValue": "false",
"defaultValue": "true",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailedTests"
},
Expand Down
29 changes: 23 additions & 6 deletions Tasks/AzureTestPlanV0/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs = require('fs');
import * as path from 'path';
import * as tl from 'azure-pipelines-task-lib/task';
import * as tr from 'azure-pipelines-task-lib/toolrunner';
import { Writable } from 'stream';

var isWindows = os.type().match(/^Win/);

Expand Down Expand Up @@ -40,11 +41,23 @@ function getMavenExec() {
return mvnExec;
}

function getExecOptions(): tr.IExecOptions {
function getExecOptions(output?: { stdout: string}): tr.IExecOptions {
var env = process.env;
return <tr.IExecOptions>{

var execOptions = output ? <tr.IExecOptions>{
env: env,
};
outStream: new Writable({
write(chunk, encoding, callback) {
output.stdout += chunk.toString();
process.stdout.write(chunk); // Stream to console
callback();
},
KathanS marked this conversation as resolved.
Show resolved Hide resolved
})
} : <tr.IExecOptions>{
env: env
}

return execOptions;
}

/**Maven orchestration occurs as follows:
Expand Down Expand Up @@ -149,12 +162,16 @@ export async function execGradleBuild(args: string[]): Promise<number> {
gradleRunner.arg('clean');
gradleRunner.arg(args);

let runnerOutput = { stdout: ''};

try {
await gradleRunner.exec(getExecOptions());
await gradleRunner.exec(getExecOptions(runnerOutput));
// Gradle build succeeded
return 0; // Return 0 indicating success
} catch (err) {
console.error(err.message);
if (runnerOutput.stdout.includes('There were failing tests')) {
return 0;
}
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
KathanS marked this conversation as resolved.
Show resolved Hide resolved
return 1; // Return 1 indicating failure
}
Expand All @@ -170,4 +187,4 @@ export async function executeJestCommand(jestPath: string, argument: string): Pr
let jest: tr.ToolRunner = tl.tool(jestPath);
jest.line(argument);
return await jest.exec(<tr.IExecOptions>{ cwd: "" });
}
}
4 changes: 2 additions & 2 deletions _generated/AzureTestPlanV0.versionmap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Default|0.248.0
Node20-225|0.248.1
Default|0.250.0
Node20-225|0.250.1
4 changes: 3 additions & 1 deletion _generated/AzureTestPlanV0/Invokers/maveninvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export async function executeMavenTests(testsToBeExecuted: string[], pomFilePath
args.push(pomFilePath);
}

args.push('-Dmaven.test.failure.ignore=true');

tl.debug("Executing java maven tests with executable : " + executable);
tl.debug("Executing java maven tests with args :" + args);

let status = await execMavenBuild(args);

return status ?? 1;
}
}
9 changes: 5 additions & 4 deletions _generated/AzureTestPlanV0/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 248,
"Minor": 250,
"Patch": 0
},
"preview": true,
Expand Down Expand Up @@ -123,7 +123,7 @@
"name": "failTaskOnFailedTests",
"type": "boolean",
"label": "Fail if there are test failures",
"defaultValue": "false",
"defaultValue": "true",
"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."
},
Expand Down Expand Up @@ -196,7 +196,8 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.248.0",
"Node20-225": "0.248.1"
"Default": "0.250.0",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.1"
}
}
9 changes: 5 additions & 4 deletions _generated/AzureTestPlanV0/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 248,
"Minor": 250,
"Patch": 0
},
"preview": true,
Expand Down Expand Up @@ -123,7 +123,7 @@
"name": "failTaskOnFailedTests",
"type": "boolean",
"label": "ms-resource:loc.input.label.failTaskOnFailedTests",
"defaultValue": "false",
"defaultValue": "true",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailedTests"
},
Expand Down Expand Up @@ -196,7 +196,8 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.248.0",
"Node20-225": "0.248.1"
"Default": "0.250.0",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.1"
}
}
29 changes: 23 additions & 6 deletions _generated/AzureTestPlanV0/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs = require('fs');
import * as path from 'path';
import * as tl from 'azure-pipelines-task-lib/task';
import * as tr from 'azure-pipelines-task-lib/toolrunner';
import { Writable } from 'stream';

var isWindows = os.type().match(/^Win/);

Expand Down Expand Up @@ -40,11 +41,23 @@ function getMavenExec() {
return mvnExec;
}

function getExecOptions(): tr.IExecOptions {
function getExecOptions(output?: { stdout: string}): tr.IExecOptions {
var env = process.env;
return <tr.IExecOptions>{

var execOptions = output ? <tr.IExecOptions>{
env: env,
};
outStream: new Writable({
write(chunk, encoding, callback) {
output.stdout += chunk.toString();
process.stdout.write(chunk); // Stream to console
callback();
},
})
} : <tr.IExecOptions>{
env: env
}

return execOptions;
}

/**Maven orchestration occurs as follows:
Expand Down Expand Up @@ -149,12 +162,16 @@ export async function execGradleBuild(args: string[]): Promise<number> {
gradleRunner.arg('clean');
gradleRunner.arg(args);

let runnerOutput = { stdout: ''};

try {
await gradleRunner.exec(getExecOptions());
await gradleRunner.exec(getExecOptions(runnerOutput));
// Gradle build succeeded
return 0; // Return 0 indicating success
} catch (err) {
console.error(err.message);
if (runnerOutput.stdout.includes('There were failing tests')) {
return 0;
}
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
return 1; // Return 1 indicating failure
}
Expand All @@ -170,4 +187,4 @@ export async function executeJestCommand(jestPath: string, argument: string): Pr
let jest: tr.ToolRunner = tl.tool(jestPath);
jest.line(argument);
return await jest.exec(<tr.IExecOptions>{ cwd: "" });
}
}
4 changes: 3 additions & 1 deletion _generated/AzureTestPlanV0_Node20/Invokers/maveninvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export async function executeMavenTests(testsToBeExecuted: string[], pomFilePath
args.push(pomFilePath);
}

args.push('-Dmaven.test.failure.ignore=true');

tl.debug("Executing java maven tests with executable : " + executable);
tl.debug("Executing java maven tests with args :" + args);

let status = await execMavenBuild(args);

return status ?? 1;
}
}
9 changes: 5 additions & 4 deletions _generated/AzureTestPlanV0_Node20/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 248,
"Minor": 250,
"Patch": 1
},
"preview": true,
Expand Down Expand Up @@ -123,7 +123,7 @@
"name": "failTaskOnFailedTests",
"type": "boolean",
"label": "Fail if there are test failures",
"defaultValue": "false",
"defaultValue": "true",
"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."
},
Expand Down Expand Up @@ -200,7 +200,8 @@
"MultipleMatchingGradlewFound": "Multiple gradlew files found. Selecting the first matched instance"
},
"_buildConfigMapping": {
"Default": "0.248.0",
"Node20-225": "0.248.1"
"Default": "0.250.0",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.1"
}
}
9 changes: 5 additions & 4 deletions _generated/AzureTestPlanV0_Node20/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "Microsoft Corporation",
"version": {
"Major": 0,
"Minor": 248,
"Minor": 250,
"Patch": 1
},
"preview": true,
Expand Down Expand Up @@ -123,7 +123,7 @@
"name": "failTaskOnFailedTests",
"type": "boolean",
"label": "ms-resource:loc.input.label.failTaskOnFailedTests",
"defaultValue": "false",
"defaultValue": "true",
"required": false,
"helpMarkDown": "ms-resource:loc.input.help.failTaskOnFailedTests"
},
Expand Down Expand Up @@ -200,7 +200,8 @@
"MultipleMatchingGradlewFound": "ms-resource:loc.messages.MultipleMatchingGradlewFound"
},
"_buildConfigMapping": {
"Default": "0.248.0",
"Node20-225": "0.248.1"
"Default": "0.250.0",
"LocalPackages": "0.249.4",
"Node20-225": "0.250.1"
}
}
29 changes: 23 additions & 6 deletions _generated/AzureTestPlanV0_Node20/testLibExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs = require('fs');
import * as path from 'path';
import * as tl from 'azure-pipelines-task-lib/task';
import * as tr from 'azure-pipelines-task-lib/toolrunner';
import { Writable } from 'stream';

var isWindows = os.type().match(/^Win/);

Expand Down Expand Up @@ -40,11 +41,23 @@ function getMavenExec() {
return mvnExec;
}

function getExecOptions(): tr.IExecOptions {
function getExecOptions(output?: { stdout: string}): tr.IExecOptions {
var env = process.env;
return <tr.IExecOptions>{

var execOptions = output ? <tr.IExecOptions>{
env: env,
};
outStream: new Writable({
write(chunk, encoding, callback) {
output.stdout += chunk.toString();
process.stdout.write(chunk); // Stream to console
callback();
},
})
} : <tr.IExecOptions>{
env: env
}

return execOptions;
}

/**Maven orchestration occurs as follows:
Expand Down Expand Up @@ -149,12 +162,16 @@ export async function execGradleBuild(args: string[]): Promise<number> {
gradleRunner.arg('clean');
gradleRunner.arg(args);

let runnerOutput = { stdout: ''};

try {
await gradleRunner.exec(getExecOptions());
await gradleRunner.exec(getExecOptions(runnerOutput));
// Gradle build succeeded
return 0; // Return 0 indicating success
} catch (err) {
console.error(err.message);
if (runnerOutput.stdout.includes('There were failing tests')) {
return 0;
}
tl.setResult(tl.TaskResult.Failed, "Build failed."); // Set the step result to Failed
return 1; // Return 1 indicating failure
}
Expand All @@ -170,4 +187,4 @@ export async function executeJestCommand(jestPath: string, argument: string): Pr
let jest: tr.ToolRunner = tl.tool(jestPath);
jest.line(argument);
return await jest.exec(<tr.IExecOptions>{ cwd: "" });
}
}