Generating Allure Trendline on Gitlab Pages
In Gitlab Pages teams find an easy solution to host and share reports. This especially is a very handy feature to host test reports.
Allure is a popular reporting choice nowadays, for teams to use it for integration test reports for both FE and BE. One of the important feature that makes this tool popular are the trendlines and a plethora of graphs.
Due to a lack of plugin support like in Jenkins, teams using Gitlab miss out on the historical information rendered through trendlines.
Let’s understand how to get the Allure Trendline using a simple hack, but before that let’s check how those trendlines are generated.
There are two folders that allure creates when its configured in a project
- allure-results
- allure-report
allure-results
folder contains all the test suite information along with the attachments. This folder is used by the allure to generate an HTML report in the folder allure-report
In some language bindings, these folder names are customisable but as a default allure uses these two folders.
The directory structure of a generated allure-report is as below.
If we take a closer look at the folders created within, the folder history
is where all the previous runs information is stored. However, this information is limited only to the current run if the allure-results
folder doesn’t have a backup from the previous run. This is the crux of generating trendlines in allure reports.
Workflow
One interesting question that comes from the above workflow is where do we save the history folder in between runs? Do we use a server to store or is there an easy approach?
Gitlab pages solve this problem for us, as this acts as a server for us at free of cost.
Let us relook at the above workflow from a GitLab pipeline perspective.
On the first run, The first stage Test will generate allure-results
folder. This is consumed by the second stage Allure to generate allure-report
folder. This folder is saved to GitLab pages in the third stage Deploy.
By this time we have allure-report of first-run successfully saved and rendered on GitLab pages.
To generate a trend line from the second run onwards we need to download the last run artefacts (a.k.a history folder) from pages
job in the Test stage.
This can be achieved with the below snippet
If your project is a private repo, create a new project deploy token with read_api
access.
This snippet can be added to your test jobs as below
Once the reports are published from the second run onwards, we can start seeing the trendline.
Additional Notes
- If you are using a custom hosted GitLab, change the host to a custom URL in
.download_history
task - Publish to pages only for one branch like
master
,release
etc so that trends are consistent.