In the previous tutorial, I discussed the Jenkins pipeline. This tutorial will discuss the steps to create the Jenkins pipeline for Serenity tests.
Pre-Requisite:
Jenkins was installed and started on the computer.
To generate Serenity Report in Jenkins, we need to download HTML Publisher. Please refer to this tutorial to install the plugin – How to install Plugins in Jenkins.
Implementation Steps
Step 1: Create a new pipeline project
- Give the Name of the project – Serenity_PipelineDemo
- Click on the pipeline project.
- Click on the OK button.

In the General section, enter the project description in the Description box.

Step 2: Scroll down to Pipeline
From the Definition field, choose the “Pipeline script from SCM” option. This option instructs Jenkins to obtain your Pipeline from Source Control Management (SCM), which will be your locally cloned Git repository.
From the SCM field, choose Git.
The Repositories section contains the Repository URL and Credentials.
In the Repository URL field, specify the directory path of the GitLab/GitHub project.
In the Credentials field, specify the username and password needed to log in to GitLab/GitHub.
In this case, I have the project is present in GitLab and using it.

Step 3: Create Jenkinsfile
Create and save a new text file with the name Jenkinsfile at the root of the project in the GitLab repository. Here, we are using the Selenium project with TestNG. To know more about the Integration of Serenity with TestNG, please refer to this tutorial – Testing of Web Application using Serenity with JUnit4.

For this tutorial, we are using Declarative syntax. The sample example is given below:
pipeline {
agent any
stages {
stage('Test') {
steps {
bat "mvn -D clean verify"
}
post {
// If Maven was able to run the tests, even if some of the test
// failed, record the test results and archive the jar file.
success {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'target/site/serenity/', reportFiles: 'index.html', reportName: 'Serenity Report', reportTitles: '', useWrapperFileDirectly: true])
}
}
}
}
}
We are publishing index.html, so it is mentioned as reportFiles and it is present in Directory – target/site/serenity.
Step 4: Specify branches to build a section under Repositories
- Branch Specifier – */master (This is my main branch)
- ScriptPath – Jenkinsfile

Click on the Apply and Save buttons.
We have created a new Maven project “Serenity_PipelineDemo” with the configuration to run the Serenity Tests with JUnit4.

Step 5: Execute the tests
Let’s execute it now by clicking on the “Build Now” button.

Right-click on Build Number (here in my case it is #3) and click on Console Output to see the result.

Below is the test execution summary.

Step 6: Pipeline Steps
Once the execution is completed, and we want to see the Pipeline Steps, click on the Pipeline Steps mentioned on the left side of the page.

Step 7: View the Report
Once the execution is completed, go back to “Serenity_PipelineDemo”. We can see below that the Serenity Report is generated.

We could see a link to view the “Serenity Report“. Click on the Serenity Report. It displays the index.html Report.

Tip: If you don’t see the Report UI intact, then you need to configure a simple groovy script. For that, go to Dashboard–>Manage Jenkins–>Script Console and add the script as:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","")

We are done! Congratulations on making it through this tutorial and hope you found it useful! Happy Learning!!
mvn -D without any options. What does this do?
I found that the stage remains green even if there are failures as the build of serenity is successful. I’ve had to parse the ‘Tests run:’ line in the output. Is there a way to overcome this?
LikeLike
mvn -D will give an error “Unable to parse command line options: Missing argument for option: D”. -D option is used when we don’t want to see all the download steps like downloading of various dependencies. The stage will be orange if any of the tests fails in the test suite and red when the execution does not happen because of any reason. The console output shows the test execution summary. If you just want to print Test run in the console, you can use echo ‘Tests run’
LikeLike