GitLab CI — Where are my JUnit test reports?

Alfonso Johan
3 min readJan 6, 2021

Recently, I had the opportunity to assist some friends who wanted to setup a CI pipeline. They were using GitLab as their choice for version control, so I headed over to gitlab.com, signed in and created a blank project. The team was developing using Java and used gradle as their build tool.

TLDR; if you want the YAML file to setup your gradle build and display the JUnit reports head to the bottom of the article or you can get it here https://gist.github.com/alfonsojohan/0e3c47c23fae7284e8a5d48ae7199806

I have never done a CI pipeline in GitLab, I have however done a few in Azure and it was pretty easy. I was expecting the same here as well. I created an empty repository, created a simple Java project with some unit tests that would always pass. GitLab itself offers the option to run CI/CD from external repositories when you create a new project, but we want to run the CI pipeline in the GitLab repo so this option was not good.

Once the blank project was created, I saw some options at the top of the page and one of the was Set up CI/CD. Great! So far so good.

CI/CD Option in blank Gitlab project.

They offer the Auto DevOps options, I didn’t try that out and decided to roll out my own. When you click on Set up CI/CD, it’ll take you to the editor for the file .gitlab-ci.yml. This is where the action happens and the pipelines are defined. After Googling around, reading some answers on Stack Overflow I managed to put together a simple build and test pipeline for my Java project. I ended with the follow YAML.

The gradle build was running fine on my local machine using the gradlew wrapper, and I expected the same when running on GitLab pipeline. Unfortunately, this was not the case. When I pushed commits to my master branch the build pipeline would fail with “Permission denied”. After scouring the GitLab forums I managed to solve this issue by setting gradlew to be executable as mentioned in this post https://forum.gitlab.com/t/gradlew-permission-denied/20881.

git update-index --chmod=+x gradlew

Just run the above command, commit and push your changes. That should get the gradle wrapper to run. The pipeline ran and completed successfully. I was really happy. Just as I was about to celebrate with another cup of coffee, I saw something disturbing. The pipeline said that no tests were executed!

When I view the test job output I could see that gradle was executing the tests and producing the JUnit report. Back to looking for answers again and this time I found it in the GitLab documentation related to CI. I know right? RTFM. I made the changes, added a failing test for fun and pushed the commit. After approximately 2 minutes, gave myself a pat on the back and went to make that cup of coffee.

Gitlab pipeline test report

To get it working you had to specify an artifact and set the correct paths. Here it is folks, a working YAML for the GitLab CI for gradle with test reports shown.

Hope this helps those looking to do the same, wishing everyone a positive 2021!

--

--