6. Jenkins and Allure Report Integration
By: Ali Pala
Tags: Selenium, Jenkins, Testing, Test Automation, Allure

Hello all! It’s time to create a Continuous Integration structure to test our codes as daily based. However, please see the blog that I published before.

What is Jenkins and why we need to use it?

“Don’t break the nightly build!” is a common rule in software development. We expect to create a freshly built daily product version every morning for our testers. Before Jenkins, a developer was testing carefully to avoid breaking the nightly build on a local machine before merging code. However, it does not guarantee that someone else could not break the build with daily commits since developers only tested in local. In other words, there was no firm guarantee that the nightly build would survive one’s commit. Jenkins is the most famous open-source Continuous Integration tool written in Java with plugins. Jenkins is used to building and testing your software projects continuously making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. It also allows you to continuously deliver your software by integrating with a large number of testing and deployment technologies.

Advantages

While Jenkins doesn’t eliminate the need to create scripts for individual steps, it does give you a faster and more robust way to integrate your entire chain of build, test, and deployment tools than you can easily build yourself. Jenkins has more than 1000 plugins to support the automation of all kinds of development tasks. Those plugins span five areas: platforms, UI, administration, source code management, and, most frequently, build management. The last well-known advantage of Jenkins is an open-source tool with great community support and easy to install.

Installation

In order to use Jenkins, you need to download first. I will teach you about using “jenkins.war” file instead of standalone installation. Go to Jenkins download page and download the latest version.

After downloading the “jenkins.war file, go to directory that Jenkins is located in and run the Jenkins WAR standalone. You can also run as a servlet in a Java application server such as Tomcat. In either case, it produces a web user interface and accepts calls to its REST API.

Run jenkins.war

Once installed, Jenkins allows you to either accept the default plugin list or choose your own plugins. Once you have picked your initial set of plugins, click the Install button and Jenkins will add them.

Jenkins Getting Started

After installation is done successfully, The Jenkins main screen comes up and displays the current build queue and Executor status and offers links to create new items (jobs), manage users, view build histories, manage Jenkins, look at your custom views, and manage your credentials.

Jenkins main screen

Create Job: Once you have Jenkins configured, it’s time to create some projects that Jenkins can build for you. The screenshot below shows the configuration web form. A new Jenkins item can be any of seven types of the job plus a folder for organizing items. Give a name your project, select “Freestyle project” item and press the “OK” button. You can also pick something else but I will explain the “Freestyle project” in this post.

As you can see, the Source Code Management tool is Git and the repository is GitHub. If you need other kinds of repositories or different online repository services, it’s just a matter of adding the appropriate plugins and rebooting Jenkins. You need to provide your repository credential in addition to “Repository URL”.

Source Code Management View

You can decide to run your build with schedule option seen below. For example, the build will be run every 6 hours as automatically.

Run Jenkins job automatically

If you want to see the other syntax examples, click the question mark icon and see the help of Jenkins regarding cron. There a quite lots of cron job example website. Here are my favorite two. freeformatter and baeldung

Jenkins cron job help

We have configured Jenkins, created a job and specify the repository and schedule. However, we also need to do some build actions in our job. For this reason, click “Add build step” and select “Execute Windows batch command”. If I explain, what the actions do, first of all go the “virtual environment” directory to use mandatory scripts in “Scripts” folder and activate virtualenv with this script:

%WORKSPACE%/venv/Scripts & activate & cd /d

After activating virtualenv start to install required libraries to use Jenkins build like your local. pip install -r %WORKSPACE%/requirements.txt

Hint: If you manage your dependencies easily on PyCharm please install “Requirements” plugin. If you use this plugin on PyCharm, you can visit the website of the packages to learn what to do you installed for your project.

Install Requirements plugin on PyCharm

It’s time to execute Pytest test with Allure Report. In order to create a test result with an “.XML” format for each test after each test execution, determine the Allure Report results folder and run the python test.

py.test -s --alluredir=%WORKSPACE%/TestSuite/test_suite.py

Blue Ocean, the Jenkins GUI

- If you’d like the latest and greatest Jenkins UI, you can use the Blue Ocean plugin, which provides a graphical user experience. You can add the Blue Ocean plugin to your existing Jenkins installation.

Jenkins Allure Report Integration

All the tests run and Project Manager or stakeholders want to see the quality of the version itself. In this case, Allure Report and Jenkins contribution may save your life because Allure Report plugin works very well in Jenkins and serves an amazing dashboard for the report. Here are the Jenkins actions to do for creating a user-friendly report on Allure. Of course, I assume that you install the Allure Report plugin into Jenkins in “Manage Plugins” :) Add a Post-build action and pick “Allure Report” option. Then, specify the path of the results. The path must be target\allure-results can not be anything else custom directory.

Allure Report configuration on Jenkins

Here is the overview of Allure Report on Jenkins! As you can see in the right hand side, Jenkins shows the trend of Allure.

Overview of Allure Report on Jenkins

You can see what is your build quality by pressing the allure icon in the corresponding build.

Allure Report Details

Okay! We have learned so many things about Continuous Integration for our Hybrid Test Automation Framework so far. The next topic will be about Slack notification for informing the stakeholders after all tests are done without checking manually the Jenkins server. See you there!