Whether working on a small or or large project, it is always crucial to have some form of testing.
At IDR Solutions we spend a lot of time on Testing. Testing is always useful and time saving and helps you know when you have broken your code base or build when you introduce changes to it. Imagine if you run your test occasionally, now after 10 commits/pushes you decide to run the test. To your surprise, the build now fails. It is very difficult to tell what commit broke the build. If not lucky, you will have to revert Ten times to trace the issue.
Now this is when Jenkins comes in handy.
What is Jenkins?
It is a continuous Integration Server. Basically, what is does is, it can be configured to runs your tests each time there is a change to your code base. In this case when your build breaks, you get a quick notification and you can tell what code change exactly broke the build.
It is built on Java so it is a 100% cross-platform tool.
Installing Jenkins
You can install Jenkins as a native application or download the war file and deploy Jenkins from it. You can get the downloads from here. I will go ahead and download the .war
.
NB if your testing will involve GUI testing, i will advice you deploy Jenkins from the war file (We use to run the native app and had problems when it came to GUI testing ).
Starting up Jenkins
On command line, type in java -jar {Path to downloaded Jenkins directory}/jenkins.war NOTE you need to have jdk installed. You should see Jenkins starting up.
localhost:8080
. This should open up Jenkins Dashboard.Setting up Email Notification
Click on Manage Jenkins -> Configure System. Scroll to email section and fill in the details and Save.
Testing your Project
I will assume your project is hosted on GitHub. To test your GitHub hosted projects, you need to install a plugin on Jenkins.
In you Jenkins dashboard go to Manage Jenkins -> Manage Plugins -> Available (Tab) and enter GitHub in the Filter field, select GitHub Plugin and click on Download now and install after restart.
localhost:8080/restart
in your browser.Adding Your First Jenkins Job
Click on create a new job or New Item. Select Freestyle project and give your Job a name. I will call mine testSA (Test Static Analysis) and click OK.
Now at you dashboard, select the job you just created and click on configure at the left side.
Fill in the spaces as follows
Description : Run Static Analysis
Tick Discard Old Builds (Up to you)
- Strategy : Log Rotation
- Days to keep builds : blank
- Max # of builds to keep : 1
Source Code Management
Select GIT
Repository URL : url to your git source code
Credentials : your credentials
Branches to build (Branch Specifier ) : */master
Build Triggers
Select Poll SCM
Schedule : *****
Build
Click add build step and select “Execute Windows batch command” for Windows or “Execute Shell” for Linux/MacOS
Now you can pass in your test build script into that Command textBox.
Post-build Actions
Click E-mail Notification Recipients – your@email.addresss
Select Send e-mail for every unstable build & Send separate e-mails to individuals who broke the build.
Now save it and lets do our first build. Click on the schedule build button.
Note This will happen each time you push to your remote repository.
You should now see something like this if it passes
Or this each time it fails
You will also get an email notification if it fails ( with the reason why it failed).
Tip
If you want to build a project using two Git repositories you can do so by using the Multiple SCMs (it is a plugin, will will have to install). You will need to configure Jenkins to pull projects to Local subdirectories.
You can install the plugin the same way we did for git. type in Multiple SCMs this time.
Hopefully you have found this quick guide useful. In the next article, i will show you how to add your own Static Analysis test using PMD.
Our software libraries allow you to
Convert PDF to HTML in Java |
Convert PDF Forms to HTML5 in Java |
Convert PDF Documents to an image in Java |
Work with PDF Documents in Java |
Read and Write AVIF, HEIC, WEBP and other image formats |