Skip to content

Setting up the Dummy JUnit Jenkins Build (Outdated)

Stephen Ritchie edited this page Apr 24, 2018 · 1 revision

Introduction

This guide is designed to help you set up a very simple Jenkins build that uses JUnit tests. Since our plugin is designed mostly off of the results of test cases, the content of the program is not important. If you look into ```TestProject`` you'll see it's just a HelloWorld program with 10 JUnit tests that can be hard-coded to pass or fail.


1 - Download the TestProject folder onto your Jenkins machine

To make a long story short, Jenkins is very particular about the directories that it can and cannot operate within. There's a lot of weird permission issues that will conflict with Maven if you have this project sitting in the wrong place.

On my MacBook , the directory I found to work was /Users/Shared/Jenkins/Home/workspace. This may very well differ across systems, but if you can find where /Jenkins is, then you'll be able to find the /workspace. Place the TestProject folder here.

2 - Configure Jenkins

2.1 - Email Server

Jenkins can't send emails on its own, so you'll need to provide it with a valid SMTP server. I used my personal gmail account for my local Jenkins instance. If you want to use a gmail account, the settings you need are below.

This settings page can be accessed through Jenkins -> Manage Jenkins -> Configure System -> Email Notification

SMTP Server: smtp.gmail.com
Use SMTP Authentication: checked
User Name: the gmail email address
Password: the password used for the account
Use SSL: checked

2.2 Maven Environment

I also found that even if you already have Maven installed, it's best to have Jenkins handle the installation. You can configure Maven from Jenkins -> Manage Jenkins -> Global Tool Configuration -> Maven. I recommend adding an installation of Maven 3.5.3. I personally have Jenkins install Maven on its own when it needs it, rather than relying on pointing Jenkins to an existing build I have to make sure is okay.

3 - Create the Jenkins build

Now that the backend of Jenkins is all configured, it's time to create the actual TestProject build. Start this by clicking New Itemfrom the Jenkins homepage. Name the build whatever you want, but select the Freestyle project option.

3.1 - General

Under General -> Advanced select Use custom workspace and make the Directory the path to the TestProject in your Jenkins workspace.

3.2 - Build Actions

3.2.1 - Invoke top-level Maven targets

Under Build you'll want to add the Invoke top-level Maven targets build step from the dropdown menu. I'm using Maven 3.5.3, which we set up when we configured Jenkins. The Goals input is simply what you append to the mvm cmd if you're working in the command line. There's a lot of different options, but I've found that clean install works well for now.

3.3 - Post-build Actions

3.3.1 - Publish JUnit test result report

This is the action that will take the JUnit reports created by Maven, and display them in the Jenkins GUI. The only option you need to edit on this Action is the Test report XMLs input, and set it to **/target/surefire-reports/*.xml

3.3.2 - Record JaCoCo coverage report

Path to exec files: **/**.exec
Path to class directories: **/classes/uky/cs498
Path to source directories: **/src/main/java/uky/cs498

3.3.3 - CS 498 | Email Notification

This action is pretty straightforward. You just need to put the emails you want in the Recipients with whitespace separating.

CAUTION: The only option that's working right now is Send e-mail for every unstable build

4 - See if it works

If everything has gone according to plan, you should be able to click Build Now from within the build you have created, and get a blue circle if everything passes. If you get a red circle, it means either a JUnit test has failed, or something else has gone wrong. If you click on a specific build you can view the console to get an idea of what may have happened.