Hygieia Build Collectors / Jenkins Cucumber

This project uses Spring Boot to package the collector as an executable JAR with dependencies.

Building and Deploying

To package the collector into an executable JAR file, run:

mvn install

Copy this file to your server and launch it using:

java -JAR jenkins-cucumber-test-collector.jar

application.properties

You will need to provide an application.properties file that contains information about how to connect to the Dashboard MongoDB database instance, as well as properties the collector requires. See the Spring Boot documentation for information about sourcing this properties file.

Sample application.properties file

# ...
# Database Name
dbname=dashboard

# Database HostName - default is localhost
dbhost=localhost

# Database Port - default is 27017
dbport=9999

# MongoDB replicaset
dbreplicaset=[false if you are not using MongoDB replicaset]
dbhostport=[host1:port1,host2:port2,host3:port3]

# Database Username - default is blank
dbusername=db

# Database Password - default is blank
dbpassword=dbpass

#Collector schedule (required)
jenkins-cucumber.cron=0 0/5 * * * *

#Jenkins server (required) - Can provide multiple
jenkins-cucumber.servers[0]=

#pattern to find cucubmer reports
jenkins-cucumber.cucumberJsonRegex=${JENKINS_CUCUMBER_JSON_FILENAME:-cucumber.json}

#Another option: If using same username/password Jenkins auth - set username/apiKey to use HTTP Basic Auth (blank=no auth)
jenkins-cucumber.username=
jenkins-cucumber.apiKey=

Jenkins Job with Cucumber

The Jenkins Cucumber Test Collector makes use of the JSON formatting output of [Cucumber] (https://cucumber.io) test cases to provide dashboard results from various Jenkins jobs.

This collector takes advantage of tools standards established for the [Jenkins Cucumber Reports Plugin] (https://wiki.jenkins-ci.org/display/JENKINS/Cucumber+Test+Result+Plugin) in the sense that it will look for the common output files generated by cucumber in the designated location to populate the collector.

Testing with Cucumber:

The setup for utilizing this collector relies heavily on the output of the Cucumber test cases. All languages that utilize cucumber should allow setting the format of the output to JSON and set the name of the output file. For the usage of this collector, all output files should be entitled cucumber.json. Since cucumber tests can be written in many languages, there are many examples of how to enable the output format. Here are a couple of examples for setting these options in Java and Ruby:

For Cucumber-JVM, the Cucumber Options should be similar to the following code snippet:

@RunWith(Cucumber.class)
@CucumberOptions( features = "src/test/features/com/sample",
    tags = { "~@wip", "@executeThis" }, monochrome = true,
    format = { "pretty", "html:target/cucumber", "json:target/cucumber.json" } )
public class RunCukeTest {

}

For Ruby Cucumber, the cucumber options for the format should be set to json and the out should designate the correct filename.

For example:

cucumber features/my_feature.feature --format json --out cucumber.json

After the cucumber.json output has been generated during a test run, collector will depend on a root directory to search for all output files that will be included in the results. If multiple projects are being executed or multiple cucumber commands are being called, then the folder structure created will provide the “suite” names for the test result report.

For example:

root_dir/
|--- project1
|    |--- cucumber.json
|--- project2
|    |--- cucumber.json
|--- project3
|    |--- cucumber.json
...
...

Jenkins setup:

The setup required in a Jenkins job is fairly simple. Assuming that the correct directory structure has been established from the above setup, archiving your root directory after the build completes is all that is required.

Select the “Archive the artifacts” Post-build action for your Jenkins job.

Next, set the files to archive to the root of your directory tree.