How To Publish ExtentReport Using Jenkins

Jenkins is a powerful automation tool that allows continuous integration and continuous delivery of projects, regardless of the platform we are working on. It is free and can be integrated with a number of testing and deployment technologies. In this article, we will see, how we can execute our tests on slave agents and publish ExtentReport Using Jenkins.

Jenkins-installation:

Jenkins installation can be done in multiple ways. We can install Jenkins locally on our system or use Docker as a container platform.

Prerequisite:

1)JDK installation and path configuration.

Jenkins Installation on Windows

Download and install Jenkins from Here. Unzip it and follow the steps. Complete the configuration and installation. After successful installation check port 8080 for Jenkins access. Open the web browser and type “localhost:8080”.

Jenkins Installation on Mac

  1. Install Homebrew.
  2. Install Jenkins using the brew command.
brew install jenkins-lts

After successful Jenkins installation and configuration start the Jenkins server using the below-mentioned command.

brew services start jenkins-lts

Jenkins Installation Using Docker

Docker is a popular platform widely used for building, testing and deploying an application using OS-level virtualization in the form of containers. In this article, I will be using Jenkins docker image to set up Jenkins.

Prerequisite:

  1. Download and set up Docker.

Once docker is installed on your machine the next step is to create a Jenkins server on docker. Follow the below-mentioned steps for Jenkins installation and configuration.

2. Pull a stable image of Jenkins from the docker hub.

docker pull jenkins/jenkins:lts

3. Create a Jenkins directory preferably not in the project directory.

mkdir jenkins

4. Navigate to the directory and execute the below command to map the Jenkins container port to our local machine port.

docker run -p 8080:8080 -p 50000:50000 -v $PWD/jenkins:/var/jenkins_home” jenkins/jenkins:lts

5. Copy the Jenkins password and save it for future reference.

6. Install all the available plugins and complete the Jenkins setup.

7. Set up Username and password for Jenkins dashboard.

Once setup is successful, you will navigate to the Jenkins Login Screen. Enter your username and password and log into the dashboard.

Configure Slave Node:

Jenkins uses a master-slave architecture to configure distributed builds. In this architecture, Master and Slave nodes communicate through TCP/IP protocol. The main Jenkins server acts as the Master node that manages slaves. A slave is a Java executable that runs on a remote machine. We can have any number of agent nodes and slave nodes.

To Configure Node, select “Manage Jenkins -> Manage Nodes And Clouds-> New Node” to create a new node.

Enter NodeName, select permanent agent, and click ok.

Agent Node setup
AgentNode

In the next screen, we need to provide a number of executors, the Remote Root directory, and the launch method. You can provide any preferable path to the Remote Root directory where you want to keep your agent machine data. We are going to use ‘Launch agent by connecting it to controller’ as the launch method. Click on save.

Slave node setup
Jenkins Master Slave setup

Click on slave.jar. A file named slave-agent.jnlp will be downloaded. Copy the command visible on the screen as ‘Run from agent command line’, Navigate to the folder from your cmd or terminal where the jar file is downloaded, and execute the command. The slave node is successfully set up and available.

Integration Steps:

Now, let’s walk through the steps to integrate ExtentReport with Jenkins:

Manage Plugins:

Navigate to the Jenkins dashboard and go to “Manage Jenkins” > “Manage Plugins.” Search for the “Extent Reports” plugin and install it. This plugin allows Jenkins to generate ExtentReport as part of the build process.

Create Freestyle Project:

Once Plugin is installed and executor nodes configured the next step is creating a project. To create a project in Jenkins, go to Dashboard–>New Item–>Freestyle Project, provide a name to the project and click on ok.

Configuration for publishing extent report:

1)Select git as source code management and provide your repository URL. Choose credentials as none if it is a public repository and mention the Branch specifier as “*/*”

Jenkins SCM configuration

2)Go to the Build Section, click on add build step, and select “invoke top-level maven target” from the dropdown. Type ‘clean install’ in the goals section. This maven command will clean previously complied binaries and build and install the JARS defined in our project’s pom.xml file.

3)Go to post-build actions, and click on add post-build steps. choose Publish HTML Reports. This ensures that the generated reports are preserved after the build is completed.

Provide the relative path where extent reports are stored and provide the exact name of the report in the index page option. Give the report title click on Apply and save.

Jenkins Post build actions

4)Now the project is configured successfully. Navigate to the project and click on Build Now. The build is triggered and after successful execution, you will see the HTML Report option in the project workspace. Click on it and you will navigate to this beautiful report.

Publish ExtentReport Using Jenkins
ExtentReport

The ExtentReport generated by Jenkins will be available in HTML format, providing an interactive and visually appealing representation of test results. You can access the report directly from the Jenkins dashboard or share the report URL with stakeholders for review.

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", "")

Conclusion

Integrating ExtentReport with Jenkins enables teams to generate comprehensive and visually appealing test results, allowing for better decision-making and communication. By following the steps outlined in this article, we can seamlessly publish ExtentReport Using Jenkins pipeline, enhancing the quality assurance process and ultimately delivering higher-quality software.

Discover more from AutomationQaHub

Subscribe now to keep reading and get access to the full archive.

Continue reading