Skip to content

Commit 372f19e

Browse files
vbraginArtem Eroshenko
authored andcommitted
add build results base on tests (fixes #13, via #167)
1 parent d35f7b4 commit 372f19e

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

src/main/java/ru/yandex/qatools/allure/jenkins/AllureReportPublisher.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.yandex.qatools.allure.jenkins;
22

3+
import com.google.common.base.Optional;
34
import hudson.EnvVars;
45
import hudson.FilePath;
56
import hudson.Launcher;
@@ -11,6 +12,7 @@
1112
import hudson.model.Action;
1213
import hudson.model.BuildListener;
1314
import hudson.model.JDK;
15+
import hudson.model.Result;
1416
import hudson.model.Run;
1517
import hudson.model.TaskListener;
1618
import hudson.tasks.BuildStepMonitor;
@@ -28,6 +30,7 @@
2830
import ru.yandex.qatools.allure.jenkins.config.ResultsConfig;
2931
import ru.yandex.qatools.allure.jenkins.exception.AllurePluginException;
3032
import ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation;
33+
import ru.yandex.qatools.allure.jenkins.utils.BuildSummary;
3134
import ru.yandex.qatools.allure.jenkins.utils.BuildUtils;
3235
import ru.yandex.qatools.allure.jenkins.utils.FilePathUtils;
3336
import ru.yandex.qatools.allure.jenkins.utils.TrueZipArchiver;
@@ -193,7 +196,13 @@ public void perform(@Nonnull Run<?, ?> run, @Nonnull FilePath workspace, @Nonnul
193196
final List<FilePath> results = new ArrayList<>();
194197

195198
final EnvVars buildEnvVars = BuildUtils.getBuildEnvVars(run, listener);
196-
for (final ResultsConfig resultsConfig : getResults()) {
199+
200+
List<ResultsConfig> resultsConfigs = getResults();
201+
if (resultsConfigs == null) {
202+
throw new AllurePluginException("The property 'Results' have to be specified!" +
203+
" Check your job's configuration.");
204+
}
205+
for (final ResultsConfig resultsConfig : resultsConfigs) {
197206
String expandedPath = buildEnvVars.expand(resultsConfig.getPath());
198207
results.addAll(workspace.act(new FindByGlob(expandedPath)));
199208
}
@@ -281,7 +290,9 @@ private void generateReport(@Nonnull List<FilePath> resultsPaths, @Nonnull Run<?
281290
}
282291
listener.getLogger().println("Allure report was successfully generated.");
283292
saveAllureArtifact(run, workspace, reportPath, listener);
284-
run.addAction(new AllureReportBuildAction(FilePathUtils.extractSummary(run)));
293+
BuildSummary buildSummary = FilePathUtils.extractSummary(run);
294+
run.addAction(new AllureReportBuildAction(buildSummary));
295+
run.setResult(buildSummary.getResult());
285296
} finally {
286297
FilePathUtils.deleteRecursive(reportPath, listener.getLogger());
287298
}

src/main/java/ru/yandex/qatools/allure/jenkins/utils/BuildSummary.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ru.yandex.qatools.allure.jenkins.utils;
22

3+
import hudson.model.Result;
4+
35
import java.util.Map;
46

57
/**
@@ -37,4 +39,11 @@ public long getBrokenCount() {
3739
public long getUnknownCount() {
3840
return getStatistic("unknown");
3941
}
42+
43+
public Result getResult() {
44+
if (getFailedCount() > 0 || getBrokenCount() > 0) {
45+
return Result.UNSTABLE;
46+
}
47+
return Result.SUCCESS;
48+
}
4049
}

src/test/java/ru/yandex/qatools/allure/jenkins/ReportGenerateIT.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public void shouldGenerateReportForParameters() throws Exception {
9191
FreeStyleBuild build = jRule.buildAndAssertSuccess(project);
9292

9393
assertThat(build.getActions(AllureReportBuildAction.class)).hasSize(1);
94-
9594
}
9695

9796
@Test
@@ -106,7 +105,16 @@ public void shouldGenerateReportForWrappedParameters() throws Exception {
106105
FreeStyleBuild build = jRule.buildAndAssertSuccess(project);
107106

108107
assertThat(build.getActions(AllureReportBuildAction.class)).hasSize(1);
108+
}
109109

110+
@Test
111+
public void shouldGenerateReportWithUnstableResult() throws Exception {
112+
FreeStyleProject project = jRule.createFreeStyleProject();
113+
project.setScm(getSimpleFileScm("sample-testsuite-with-failed.xml", ALLURE_RESULTS));
114+
project.getPublishersList().add(createAllurePublisher("allure-results"));
115+
FreeStyleBuild build = jRule.assertBuildStatus(Result.UNSTABLE, project.scheduleBuild2(0));
116+
117+
assertThat(build.getActions(AllureReportBuildAction.class)).hasSize(1);
110118
}
111119

112120
@Test
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<ns2:test-suite xmlns:ns2="urn:model.allure.qatools.yandex.ru" start="1412949538848" stop="1412949560045"
3+
version="1.4.4-SNAPSHOT">
4+
<name>my.company.Sample</name>
5+
<test-cases>
6+
<test-case start="1412949539363" stop="1412949539730" status="passed">
7+
<name>sampleTestCase</name>
8+
</test-case>
9+
<test-case start="1412949539800" stop="1412949539900" status="failed">
10+
<name>sampleFailedTestCase</name>
11+
<failure>
12+
<message>Failed test!</message>
13+
<stack-trace>
14+
Failed stack trace!
15+
</stack-trace>
16+
</failure>
17+
</test-case>
18+
</test-cases>
19+
</ns2:test-suite>

0 commit comments

Comments
 (0)