Skip to content

Commit aea5873

Browse files
authored
Merge pull request #155 from MarkEWaite/add-pipeline-symbol
Add `testNG` symbol for Pipeline syntax clarity
2 parents 36dde98 + 48bed48 commit aea5873

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

README.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,39 @@ Results**. This option allows you to configure the following properties:
8787

8888
### Pipeline in Jenkinsfile
8989

90+
The link:https://www.jenkins.io/redirect/pipeline-snippet-generator[Pipeline Syntax Snippet Generator] guides the user to select TestNG report options.
91+
Add the `testNG` step to declarative Pipeline in a `post` section.
92+
9093
```
9194
post {
9295
always {
93-
step([$class: 'Publisher', reportFilenamePattern: '**/testng-results.xml'])
96+
testNG()
9497
}
9598
}
9699
```
97100

101+
Additional options can be included in the testNG declarative Pipeline step like this:
102+
103+
```
104+
post {
105+
always {
106+
testNG(showFailedBuilds: true,
107+
unstableFails: 5, unstableSkips: 25,
108+
failedFails: 10, failedSkips: 50)
109+
}
110+
}
111+
```
112+
113+
The `testNG` Pipeline step can be used in a scripted Pipeline like this:
114+
115+
```
116+
node {
117+
// Add steps that run TestNG tests
118+
// Publish TestNG report with the `testNG()` step
119+
testNG(reportFilenamePattern: '**/testng-many-results.xml')
120+
}
121+
```
122+
98123
### Properties
99124

100125
Some TestNG plugin properties can only be controlled by command line properties set at Jenkins startup.

src/main/java/hudson/plugins/testng/Publisher.java

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import hudson.util.FormValidation;
2626
import jenkins.tasks.SimpleBuildStep;
2727
import net.sf.json.JSONObject;
28+
import org.jenkinsci.Symbol;
2829
import org.kohsuke.stapler.*;
2930
import org.kohsuke.stapler.verb.POST;
3031

@@ -442,6 +443,7 @@ static boolean saveReports(FilePath testngDir, FilePath[] paths, PrintStream log
442443
return true;
443444
}
444445

446+
@Symbol("testNG")
445447
public static final class DescriptorImpl extends BuildStepDescriptor<hudson.tasks.Publisher> {
446448

447449
/**

src/test/java/hudson/plugins/testng/TestNGTestResultBuildActionTest.java

+23
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,29 @@ public void test_threshold_for_fails_default_pipeline() throws Exception {
400400
r.assertLogContains("tests failed, which exceeded threshold of 0%. Marking build as UNSTABLE", build);
401401
}
402402

403+
@Issue("JENKINS-27121")
404+
@Test
405+
public void test_threshold_for_fails_default_pipeline_using_symbol() throws Exception {
406+
if (isWindows()) {
407+
/* Fails to delete a file on Windows agents of ci.jenkins.io.
408+
* Likely indicates a bug somewhere, but I'd rather have most
409+
* of the tests passing on ci.jenkins.io Windows rather than
410+
* blocking all Windows tests until this can be investigated.
411+
*/
412+
return;
413+
}
414+
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
415+
String contents = CommonUtil.getContents(Constants.TESTNG_FAILED_TEST);
416+
p.setDefinition(new CpsFlowDefinition("node {\n writeFile(file: 'testng-results.xml', text: '''" + contents + "''')\n testNG()\n}\n", true));
417+
WorkflowRun build = p.scheduleBuild2(0).get();
418+
r.assertBuildStatus(Result.UNSTABLE, build);
419+
TestNGTestResultBuildAction action = build.getAction(TestNGTestResultBuildAction.class);
420+
assertNotNull(action);
421+
TestNGResult result = action.getResult();
422+
assertEquals("checking result details", "TestNGResult {totalTests=2, failedTests=1, skippedTests=0, failedConfigs=0, skippedConfigs=0}", result.toString());
423+
r.assertLogContains("tests failed, which exceeded threshold of 0%. Marking build as UNSTABLE", build);
424+
}
425+
403426
@Test
404427
public void test_threshold_for_fails_failure() throws Exception {
405428
FreeStyleProject p = r.createFreeStyleProject();

0 commit comments

Comments
 (0)