Skip to content

Commit 5bdcd19

Browse files
committed
Fixing publish test results in gradle task
1 parent 60f0f93 commit 5bdcd19

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
lines changed

Tasks/Gradle/gradletask.ts

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if (isWindows) {
5858
tl.debug("Append .bat extension name to gradlew script.");
5959
wrapperScript += '.bat';
6060
}
61-
}
61+
}
6262

6363
if (fs.existsSync(wrapperScript)) {
6464
// (The exists check above is not necessary, but we need to avoid this call when we are running L0 tests.)
@@ -116,7 +116,7 @@ if (javaHomeSelection == 'JDKVersion') {
116116
specifiedJavaHome = readJavaHomeFromRegistry(jdkVersion, jdkArchitecture);
117117
}
118118

119-
if (!specifiedJavaHome) {
119+
if (!specifiedJavaHome) {
120120
throw new Error('Failed to find specified JDK version. Please make sure environment variable ' + envName + ' exists and is set to the location of a corresponding JDK.');
121121
}
122122
}
@@ -131,36 +131,47 @@ if (specifiedJavaHome) {
131131
tl.debug('Set JAVA_HOME to ' + specifiedJavaHome);
132132
process.env['JAVA_HOME'] = specifiedJavaHome;
133133
}
134-
134+
135135
/* Actual execution of Build and further flows*/
136136
async function execBuild() {
137137
await execEnableCodeCoverage();
138138
if (reportingTaskName && reportingTaskName != "") {
139139
gb.arg(reportingTaskName);
140140
}
141-
141+
142142
enableSonarQubeAnalysis();
143143
var gradleResult;
144+
var statusFailed = false;
144145
gb.exec()
145146
.then(function (code) {
146147
gradleResult = code;
147148
tl.debug(`exit code: ${code}`);
148-
publishTestResults(publishJUnitResults, testResultsFiles);
149-
publishCodeCoverage(isCodeCoverageOpted);
150149
return processCodeAnalysisResults();
151150
})
152151
.then(() => {
153152
tl.debug(`Gradle result: ${gradleResult}`);
154-
if (gradleResult === 0) {
155-
tl.setResult(tl.TaskResult.Succeeded, "Build succeeded.");
156-
} else {
157-
tl.setResult(tl.TaskResult.Failed, "Build failed.");
158-
}
153+
return Q.resolve("Success");
159154
})
160155
.fail(function (err) {
161156
console.error(err);
162157
tl.debug('taskRunner fail');
163-
tl.setResult(tl.TaskResult.Failed, err);
158+
gradleResult = -1;
159+
statusFailed = true;
160+
return Q.resolve(err);
161+
})
162+
.then(function (resp) {
163+
// We should always publish test results and code coverage
164+
publishTestResults(publishJUnitResults, testResultsFiles);
165+
publishCodeCoverage(isCodeCoverageOpted);
166+
167+
if (gradleResult === 0) {
168+
tl.setResult(tl.TaskResult.Succeeded, "Build succeeded.");
169+
} else if (gradleResult === -1 && statusFailed === true) {
170+
tl.setResult(tl.TaskResult.Failed, resp);
171+
}
172+
else {
173+
tl.setResult(tl.TaskResult.Failed, "Build failed.");
174+
}
164175
});
165176
}
166177

Tasks/Gradle/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"version": {
1313
"Major": 1,
1414
"Minor": 0,
15-
"Patch": 59
15+
"Patch": 60
1616
},
1717
"demands": [
1818
"java"

Tasks/Gradle/task.loc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"version": {
1313
"Major": 1,
1414
"Minor": 0,
15-
"Patch": 59
15+
"Patch": 60
1616
},
1717
"demands": [
1818
"java"

0 commit comments

Comments
 (0)