Jenkins Continuous Integration Cookbook - Second Edition
Jenkins is an award-wining and one of the most popular Continuous Integration servers in the market today. It was designed to maintain, secure, communicate, test, build, and improve the software development process.
This book starts by examining the most common maintenance tasks. This is followed by steps that enable you to enhance the overall security of Jenkins. You will then explore the relationship between Jenkins builds and Maven pom.xml. Then, you will learn how to use plugins to display code metrics and fail builds to improve quality, followed by how to run performance and functional tests against a web application and web services. Finally, you will see what the available plugins are, concluding with best practices to improve quality.
Read an Extract from the book
Analyzing project data with the R plugin
This recipe describes how to use R to process metrics on each file in your project workspace. The recipe does this by traversing the workspace and collecting a list of files of a particular extension such as Java. The R script then analyzes each file individually and finally plots the results in a graphical format to a PDF file. The workflow is common to almost all quality-related analysis of software projects. This recipe is easily customized for tasks that are more complex.
In this example, we are looking at the size in words of the text files, printing to the console the names of large files and plotting the sizes of all files. From the visual representation, you can easily see which files are particularly large. If your property file is much larger than the other property files, it is probably corrupt. If a Java file is too large, it is difficult to read and understand.
How to do it...
This feels like a well-balanced project, as there are only a few files that have a large number of lines of code.
How it works...
You loaded in the profile2 tool from subversion https://source.sakaiproject.org/svn/profile2/trunk. This code is used by millions of students around the world and represents mature, realistic production code.
Within your R script, you defined a function that takes a filename as input and then reads the file into a text object. The function then checks to see whether the number of lines is greater than 500. If it is greater than 500 lines then the filename is printed to the console output. Finally, the function returns the number of lines in the text file.
Next, the script discovers the property and Java files under the workspace. The file search is filtered by the value defined in the pattern argument. In this case, .java:
The list of filenames is passed one name at a time to the processFile function you have previously defined. The results are a list of file lengths that are stored in the resultJava and resultProperties objects:
The warnings() function produces a list of issues generated while running the sapply command:
This is stating that a new line was expected at the end of the file. It is not a critical issue. Showing the warnings is a helpful approach to discovering corrupted files.
Finally, we generate two histograms of the results, one for the Java file and the other for the properties files. The filename is created from a constant string followed by the BUILD_NUMBER environment variable that is set uniquely for each build. The pdf function tells R that the output is to be stored in a PDF file and the hist function draws a histogram of the results:
When writing R code for processing your files, don't reinvent the wheel. R has many libraries for manipulating text. The stringi library is one example (http://cran.r-project.org/web/packages/stringi/stringi.pdf). Here is some example code that counts the number of words in a text file:
The script defines the function processFile. The function requires a filename. The file is read into the stri_stats_latex function. This function is included in the stringi library. It returns a summary of the file as a vector (a series of numbers).
The file.choose() function pops up a dialog that allows you to browse your file system and choose a file. The call returns the fully qualified path to the file. It passes the value to the processFile function call. The results are stored in the results vector. The script then prints out the fourth number that is the number of words in the file.
|Course Length||12 hours 14 minutes|
|Date Of Publication||30 Jan 2015|