In the last article, carried in the October 2013 issue of Open Source For You, I gave readers a brief introduction to Jenkins and how to get started with it. Now, let’s explore some very useful and innovative Jenkins plugins and features, while learning how to use them.
As discussed earlier, Jenkins is not only about building a project periodically and sending updates about the status, but has greater capabilities! For example, with Jenkins plugins, you can use Jenkins as an Android app development framework or a monitoring tool for cron jobs run in Linux, or use it for file tracking, and so on. Jenkins currently has hundreds of such plugins available. Let’s look at some of these plugins and how to configure Jenkins.
The Android emulator plugin
This is one of the most innovative and, of course, useful features of Jenkins. With the plugin installed, Jenkins allows you to build and run an Android Apk file on an Android virtual machine. So, tasks like SDK installation, build file generation, emulator creation and launching, Apk installation/ uninstallation, monkey testing and analysis-all can be done automatically once Jenkins is configured. Let’s look at how to install this plugin and then configure Jenkins for Android app development.
To install the plugin, click on the Manage Jenkins link on the left side of the page and then click the Manage plugins link. In the page that appears, click on the tab called Available and scroll down to find the Android Emulator plugin. Just click on the check box and then press either one of the buttons to install the plugin. As you click the button, Jenkins automatically prepares and downloads the plugin along with any other plugins that are required.
After installation, you can check and change the settings for the plugin in the main configuration page, that is Manage Jenkins?Configure System. You find a new field here for Android, once the plugin is installed.
Once installed, you can start using the plugin in a way that is similar to a typical Jenkins job. Just create a freestyle Jenkins job and then click the Configure link on the left side of the page. In the configuration page, you can see the new options for Android under ‘Add build step’. Here you can select the proper actions as you wish for your Android code (Figure 1).
Cloud related plugins
Another interesting type of plugin available for Jenkins is the cloud related JClouds, which adds cloud capabilities to your Jenkins installation. With this plugin, you can launch Jenkins slaves from any cloud provider supported by JClouds. So, if you are running low on hardware at your premises and need a quick status report of your software releases, you can use this plugin and start Jenkins slaves in the cloud to run, build and execute your software.
Plugin installation is the same as discussed earlier. Once installed, configuration is needed. To configure, go to the Cloud section in the Jenkins configuration page, click on Add a new cloud and then select Cloud (JCloud). In the page that follows, fill in the configuration options. To run your build on the newly configured slave computer, just enable the Restrict where this project can be run option in the build configuration page. Enter the label, which you choose for the instance template in the Label Expression text field. For more details, you can also check the JCloud plugin page.
Monitoring external jobs
Jenkins also allows you to monitor tasks running outside. Generally, you will need to call the Jenkins plugin from the external job you want to monitor. To get started, you must install plugins like Monitoring external jobs and then configure the external job. So, if you want to monitor a cron job on your Linux server, you need to first create a new job with the option Monitor an external job. Then add the following code to your cron script:
sudo apt-get install jenkins-external-tool-monitor # obviously you should replace localhost with a FQDN if you want to # run jobs from other machines.
export JENKINS_HOME=http://@sorins.uk.xensource.com:8080/export JENKINS_HOME=http://@localhost:8080/ java -jar /usr/share/jenkins/external-job-monitor/java/jenkins-core-*.jar 'external-build-job-name' command-to-run java -jar /usr/share/jenkins/external-job-monitor/java/jenkins-core-*.jar 'external-build-test' ls -l
Note that the script is for Debian/Ubuntu Linux. You may need to change JENKINS-HOME depending on your environment. Once done, run the following commands at the command prompt to start monitoring:
$ export JENKINS_HOME=http://user:[email protected]/path/to/ jenkins/ $ java -jar /path/to/WEB-INF/lib/jenkins-core-*.jar "job name" <program arg1 arg2...>
Source: Jenkins plugin support page
With this, you can expect mails sent by Jenkins about the status of the job.
Software projects generally involve many people working on multiple files and so versioning is an uphill task. Jenkins comes to your rescue here as well. The file finger printing feature lets Jenkins track which builds created which jar file, which project is using which jar files, and so on. This feature works very well, especially in big projects with a large number of components. Note that this is an inbuilt Jenkins feature and not a plugin.
To set up this feature, go to the project, and click Configure on the left side navigation panel. Then click on the button to add post-build action. From the drop down menu, select ‘Record fingerprints of files to track usage’. Here, you can select the file extension types to be tracked by Jenkins.
We finish our series on Jenkins with this. Hope this helps you in setting up and using Jenkins for your software development. Any questions or feedback are always welcome.