Jenkins - CI Tool-End To End Platform Design
Jenkins - CI Tool-End To End Platform Design
Hello every one, Thank you for your great support to make me another review of
Automation Tools, Today we are going to see the Hands on Tour of Jenkins.
What is Jenkins?
Jenkins is an open source automation tool written in Java with plugins built for Continuous
Integration purpose. Jenkins is used to build and test your software projects continuously
making it easier for developers to integrate changes to the project, and making it easier for
users to obtain a fresh build. It also allows you to continuously deliver your software by
integrating with a large number of testing and deployment technologies. With Jenkins,
organizations can accelerate the software development process through automation. Jenkins
integrates development life-cycle processes of all kinds, including build, document, test,
package, stage, deploy, static analysis and much more.
Jenkins achieves Continuous Integration with the help of plugins. Plugins allows the
integration of Various DevOps stages. If you want to integrate a particular tool, you need to
install the plugins for that tool. For example: Git, Maven 2 project, Amazon EC2, HTML
publisher etc.
Why Jenkins?
Jenkins is software that allows continuous integration. Jenkins will be installed on a server
where the central build will take place. The following flowchart demonstrates a very simple
workflow of how Jenkins works.
Architect of Jenkins:
Along with Jenkins, sometimes, one might also see the association of Hudson. Hudson is a
very popular open-source Java-based continuous integration tool developed by Sun
Microsystems which was later acquired by Oracle. After the acquisition of Sun by Oracle, a
fork was created from the Hudson source code, which brought about the introduction of
Jenkins.
System Requirements
Disk Space No minimum requirement. Note that since all builds will be
stored on the Jenkins machines, it has to be ensured that
sufficient disk space is available for build storage.
Java Container The WAR file can be run in any container that supports
Servlet 2.4/JSP 2.0 or later.(An example is Tomcat 5).
Jenkins - Installation
Download Jenkins
The official website for Jenkins is Jenkins. If you click the given link, you can get the home
page of the Jenkins official website as shown below.
By default, the latest release and the Long-Term support release will be available for
download. The past releases are also available for download. Click the Long-Term Support
Release tab in the download section.
Click the link “Older but stable version” to download the Jenkins war file.
Starting Jenkins
Open the command prompt. From the command prompt, browse to the directory where the
jenkins.war file is present. Run the following command
OS Task Command
OS Output
We assume the readers of this tutorial have Java 1.7.0_60 installed on their system before
proceeding for this tutorial.
In case you do not have Java JDK, you can download it from the link Oracle
Set the JAVA_HOME environment variable to point to the base directory location where
Java is installed on your machine. For example,
OS Output
Append the full path of the Java compiler location to the System Path.
OS Output
Now open the command prompt. From the command prompt, browse to the directory where
the tomcat7 folder is location. Browse to the bin directory in this folder and run the start.bat
file
E:\Apps\tomcat7\bin>startup.bat
Once the processing is complete without major errors, the following line will come in the
output of the command prompt.
In the next screen, click the Available tab. This tab will give a list of plugins which are
available for downloading. In the ‘Filter’ tab type ‘Git plugin’
The list will then be filtered. Check the Git Plugin option and click on the button ‘Install
without restart’
The installation will then begin and the screen will be refreshed to show the status of the
download.
Once all installations are complete, restart Jenkins by issue the following command in the
browser. http://localhost:8080/jenkins/restart
After Jenkins is restarted, Git will be available as an option whilst configuring jobs. To
verify, click on New Item in the menu options for Jenkins. Then enter a name for a job, in
the following case, the name entered is ‘Demo’. Select ‘Freestyle project’ as the item type.
Click the Ok button.
In the next screen, if you browse to the Source code Management section, you will now see
‘Git’ as an option.
Jenkins – Maven Setup
In the Configure system screen, scroll down till you see the Maven section and then click on
the ‘Add Maven’ button.
Uncheck the ‘Install automatically’ option.
Add any name for the setting and the location of the MAVEN_HOME.
So one can get the various configuration options for Jenkins by clicking the ‘Manage
Jenkins’ option from the left hand menu side.
You will then be presented with the following screen −
Click on Configure system. Discussed below are some of the Jenkins configuration settings
which can be carried out.
The following example will use the first option of setting the "JENKINS_HOME"
environment variable.
First create a new folder E:\Apps\Jenkins. Copy all the contents from the existing ~/.jenkins
to this new directory.
Set the JENKINS_HOME environment variable to point to the base directory location where
Java is installed on your machine. For example,
OS Output
In the Jenkins dashboard, click Manage Jenkins from the left hand side menu. Then click on
‘Configure System’ from the right hand side.
In the Home directory, you will now see the new directory which has been configured.
# of executors
This refers to the total number of concurrent job executions that can take place on the
Jenkins machine. This can be changed based on requirements. Sometimes the
recommendation is to keep this number the same as the number of CPU on the machines for
better performance.
Environment Variables
This is used to add custom environment variables which will apply to all the jobs. These are
key-value pairs and can be accessed and used in Builds wherever required.
Jenkins URL
By default, the Jenkins URL points to localhost. If you have a domain name setup for your
machine, set this to the domain name else overwrite localhost with IP of machine. This will
help in setting up slaves and while sending out links using the email as you can directly
access the Jenkins URL using the environment variable JENKINS_URL which can be
accessed as ${JENKINS_URL}.
Email Notification
In the email Notification area, you can configure the SMTP settings for sending out emails.
This is required for Jenkins to connect to the SMTP mail server and send out emails to the
recipient list.
Jenkins - Management
To manage Jenkins, click on the ‘Manage Jenkins’ option from the left hand menu side.
So one can get the various configuration options for Jenkins by clicking the ‘Manage
Jenkins’ option from the left hand menu side.
You will then be presented with the following screen −
Some of the management options are as follows −
Configure System
This is where one can manage paths to the various tools to use in builds, such as the JDKs,
the versions of Ant and Maven, as well as security options, email servers, and other system-
wide configuration details. When plugins are installed. Jenkins will add the required
configuration fields dynamically after the plugins are installed.
System Information
This screen displays a list of all the current Java system properties and system environment
variables. Here one can check exactly what version of Java Jenkins is running in, what user
it is running under, and so forth.
The following screenshot shows some of the name-value information available in this
section.
System Log
The System Log screen is a convenient way to view the Jenkins log files in real time. Again,
the main use of this screen is for troubleshooting.
Load Statistics
This pages displays graphical data on how busy the Jenkins instance is in terms of the
number of concurrent builds and the length of the build queue which gives an idea of how
long your builds need to wait before being executed. These statistics can give a good idea of
whether extra capacity or extra build nodes is required from an infrastructure perspective.
Script Console
This screen lets you run Groovy scripts on the server. It is useful for advanced
troubleshooting since it requires a strong knowledge of the internal Jenkins architecture.
Manage nodes
Jenkins is capable of handling parallel and distributed builds. In this screen, you can
configure how many builds you want. Jenkins runs simultaneously, and, if you are using
distributed builds, set up build nodes. A build node is another machine that Jenkins can use
to execute its builds.
Prepare for Shutdown
If there is a need to shut down Jenkins, or the server Jenkins is running on, it is best not to
do so when a build is being executed. To shut down Jenkins cleanly, you can use the Prepare
for Shutdown link, which prevents any new builds from being started. Eventually, when all
of the current builds have finished, one will be able to shut down Jenkins cleanly.
Step 2 − In the next screen, enter the Item name, in this case we have named it Hello world.
Choose the ‘Freestyle project option’
Step 3 − The following screen will come up in which you can specify the details of the job.
Step 4 − We need to specify the location of files which need to be built. In this example, we
will assume that a local git repository(E:\Program) has been setup which contains a
‘HelloWorld.java’ file. Hence scroll down and click on the Git option and enter the URL of
the local git repository.
Note − If you repository if hosted on Github, you can also enter the url of that repository
here. In addition to this, you would need to click on the Add button for the credentials to add
a user name and password to the github repository so that the code can be picked up from
the remote repository.
Step 5 − Now go to the Build section and click on Add build step → Execute Windows
batch command
Step 6 − In the command window, enter the following commands and then click on the Save
button.
Javac HelloWorld.java
Java HelloWorld
Step 7 − Once saved, you can click on the Build Now option to see if you have successfully
defined the job.
Step 8 − Once the build is scheduled, it will run. The following Build history section shows
that a build is in progress.
Step 9 − Once the build is completed, a status of the build will show if the build was
successful or not. In our case, the following build has been executed successfully. Click on
the #1 in the Build history to bring up the details of the build.
Step 10 − Click on the Console Output link to see the details of the build
Apart from the steps shown above there are just so many ways to create a build job, the
options available are many, which what makes Jenkins such a fantastic continuous
deployment tool.
Once the build is completed, a status of the build will show if the build was successful or
not. In the Build output information, you will now notice an additional section called Test
Result. In our case, we entered a negative Test case so that the result would fail just as an
example.
One can go to the Console output to see further information. But what’s more interesting is
that if you click on Test Result, you will now see a drill down of the Test results.
Jenkins - Automated Testing
One of the basic principles of Continuous Integration is that a build should be verifiable.
You have to be able to objectively determine whether a particular build is ready to proceed
to the next stage of the build process, and the most convenient way to do this is to use
automated tests. Without proper automated testing, you find yourself having to retain many
build artifacts and test them by hand, which is hardly in the spirit of Continuous Integration.
The following example shows how to use Selenium to run automated web tests.
Step 4 − Configure the selenium server jar and click on the Save button.
Note − The selenium jar file can be downloaded from the location SeleniumHQ
Step 7 − Add the necessary details for the selenium test. Here the suiteFile is the TestSuite
generated by using the Selenium IDE. Click on Save and execute a build. Now the post
build will launch the selenium driver, and execute the html test.
Jenkins - Notification
Jenkins comes with an out of box facility to add an email notification for a build project.
• "Format" − This is the notification payload format which can either be JSON or
XML.
• "Protocol" − protocol to use for sending notification messages, HTTP, TCP or UDP.
• "Event" − The job events that trigger notifications: Job Started, Job Completed, Job
Finalized or All Events (the default option).
• "URL" − URL to send notifications to. It takes the form of "http://host" for HTTP
protocol, and "host:port" for TCP and UDP protocols.
Jenkins - Reporting
As demonstrated in the earlier section, there are many reporting plugins available with the
simplest one being the reports available for jUnit tests.
In the Post-build action for any job, you can define the reports to be created. After the builds
are complete, the Test Results option will be available for further drill-down.
Additionally the add-on plugin Static Analysis Collector is available that combines the
individual results of these plugins into a single trend graph and view.
A slave is a computer that is set up to offload build projects from the master and once setup
this distribution of tasks is fairly automatic. The exact delegation behavior depends on the
configuration of each project; some projects may choose to "stick" to a particular machine
for a build, while others may choose to roam freely between slaves.
Since each slave runs a separate program called a "slave agent" there is no need to install the
full Jenkins (package or compiled binaries) on a slave. There are various ways to start slave
agents, but in the end the slave agent and Jenkins master needs to establish a bi-directional
communication link (for example a TCP/IP socket.) in order to operate.
Step 1 − Go to the Manage Jenkins section and scroll down to the section of Manage Nodes.
Step 1 − Go to Manage Jenkins → Manage Plugins. Go to the Available section and find the
plugin “Deploy to container Plugin” and install the plugin. Restart the Jenkins server.
This plugin takes a war/ear file and deploys that to a running remote application server at the
end of a build.
Tomcat 4.x/5.x/6.x/7.x
JBoss 3.x/4.x
Glassfish 2.x/3.x
Step 2 − Go to your Build project and click the Configure option. Choose the option
“Deploy war/ear to a container”
Step 3 − In the Deploy war/ear to a container section, enter the required details of the server
on which the files need to be deployed and click on the Save button. These steps will now
ensure that the necessary files get deployed to the necessary container after a successful
build.
Jenkins - Metrics & Trends
There are various plugins which are available in Jenkins to showcase metrics for builds
which are carried out over a period of time. These metrics are useful to understand your
builds and how frequently they fail/pass over time. As an example, let’s look at the ‘Build
History Metrics plugin’.
This plugin calculates the following metrics for all of the builds once installed
To see overall trends in Jenkins, there are plugins available to gather information from
within the builds and Jenkins and display them in a graphical format. One example of such a
plugin is the ‘Hudson global-build-stats plugin’. So let’s go through the steps for this.
Step 5 − Go to the Jenkins dashboard and click on Manage Jenkins. In the Manage Jenkins
screen, scroll down and now you will now see an option called ‘Global Build Stats’. Click
on this link.
Step 6 − Click on the button ‘Initialize stats’. What this does is that it gather’s all the
existing records for builds which have already been carried out and charts can be created
based on these results.
Step 7 − Once the data has been initialized, it’s time to create a new chart. Click on the
‘Create new chart’ link.
Step 8 − A pop-up will come to enter relevant information for the new chart details. Enter
the following mandatory information
URL Options
The following commands when appended to the Jenkins instance URL will carry out the
relevant actions on the Jenkins instance.
Another best practice is to write cron jobs or maintenance tasks that can carry out clean-up
operations to avoid the disk where Jenkins is setup from becoming full.
Jenkins provides good support for providing continuous deployment and delivery. If you
look at the flow of any software development through deployment, it will be as shown
below.
The main part of Continuous deployment is to ensure that the entire process which is shown
above is automated. Jenkins achieves all of this via various plugins, one of them being the
“Deploy to container Plugin” which was seen in the earlier lessons.
There are plugins available which can actually give you a graphical representation of the
Continuous deployment process. But first lets create another project in Jenkins, so that we
can see best how this works.
Let’s create a simple project which emulates the QA stage, and does a test of the Helloworld
application.
Step 1 − Go to the Jenkins dashboard and click on New Item. Choose a ‘Freestyle project’
and enter the project name as ‘QA’. Click on the Ok button to create the project.
Step 2 − In this example, we are keeping it simple and just using this project to execute a
test program for the Helloworld application.
So our project QA is now setup. You can do a build to see if it builds properly.
Step 3 − Now go to you Helloworld project and click on the Configure option
Step 4 − In the project configuration, choose the ‘Add post-build action’ and choose ‘Build
other projects’
Step 5 − In the ‘Project to build’ section, enter QA as the project name to build. You can
leave the option as default of ‘Trigger only if build is stable’. Click on the Save button.
Step 6 − Build the Helloworld project. Now if you see the Console output, you will also see
that after the Helloworld project is successfully built, the build of the QA project will also
happen.
Step 7 − Let now install the Delivery pipeline plugin. Go to Manage Jenkins → Manage
Plugin’s. In the available tab, search for ‘Delivery Pipeline Plugin’. Click On Install without
Restart. Once done, restart the Jenkins instance.
Step 8 − To see the Delivery pipeline in action, in the Jenkins Dashboard, click on the +
symbol in the Tab next to the ‘All’ Tab.
Step 9 − Enter any name for the View name and choose the option ‘Delivery Pipeline View’.
Step 10 − In the next screen, you can leave the default options. One can change the
following settings −
You will now see a great view of the entire delivery pipeline and you will be able to see the
status of each project in the entire pipeline.
Another famous plugin is the build pipeline plugin. Let’s take a look at this.
Step 1 − Go to Manage Jenkins → Manage Plugin’s. In the available tab, search for ‘Build
Pipeline Plugin’. Click On Install without Restart. Once done, restart the Jenkins instance.
Step 2 − To see the Build pipeline in action, in the Jenkins Dashboard, click on the + symbol
in the Tab next to the ‘All’ Tab.
Step 3 − Enter any name for the View name and choose the option ‘Build Pipeline View’.
Step 4 − Accept the default settings, just in the Selected Initial job, ensure to enter the name
of the Helloworld project. Click on the Ok button.
You will now see a great view of the entire delivery pipeline and you will be able to see the
status of each project in the entire pipeline.
Jenkins - Managing Plugins
To get the list of all plugins available within Jenkins, one can visit the link
− https://wiki.jenkins-ci.org/display/JENKINS/Plugins
We’ve already seen many instances for installing plugins, let’s look at some other
maintenance tasks with regards to plugins
Uninstalling Plugins
To uninstall a plugin, Go to Manage Jenkins → Manage plugins. Click on the Installed tab.
Some of the plugins will have the Uninstall option. You can click these buttons to uninstall
the plugins. Ensure to restart your Jenkins instance after the uninstallation.
Installing another Version of a Plugin
Sometimes it may be required to install an older version of a plugin, in such a case, you can
download the plugin from the relevant plugin page on the Jenkins web site. You can then
use the Upload option to upload the plugin manually.
Jenkins - Security
In Jenkins you have the ability to setup users and their relevant permissions on the Jenkins
instance. By default you will not want everyone to be able to define jobs or other
administrative tasks in Jenkins. So Jenkins has the ability to have a security configuration in
place.
Step 1 − Click on Manage Jenkins and choose the ‘Configure Global Security’ option.
Step 2 − Click on Enable Security option. As an example, let’s assume that we want Jenkins
to maintain it’s own database of users, so in the Security Realm, choose the option of
‘Jenkins’ own user database’.
By default you would want a central administrator to define users in the system, hence
ensure the ‘Allow users to sign up’ option is unselected. You can leave the rest as it is for
now and click the Save button.
Step 3 − You will be prompted to add your first user. As an example, we are setting up an
admin users for the system.
Step 4 − It’s now time to setup your users in the system. Now when you go to Manage
Jenkins, and scroll down, you will see a ‘Manage Users’ option. Click this option.
Step 5 − Just like you defined your admin user, start creating other users for the system. As
an example, we are just creating another user called ‘user’.
Step 6 − Now it’s time to setup your authorizations, basically who has access to what. Go to
Manage Jenkins → Configure Global Security.
Click on the Save button once you have defined the relevant authorizations.
Note − For Windows AD authentication, one has to add the Active Directory plugin to
Jenkins.
Step 1 − Click on Manage Jenkins and choose the ‘Manage Plugins’ option.
Step 2 − In the available tab, search for ‘Backup Plugin’. Click On Install without Restart.
Once done, restart the Jenkins instance
Step 3 − Now when you go to Manage Jenkins, and scroll down you will see ‘Backup
Manager’ as an option. Click on this option.
Step 4 − Click on Setup.
Step 5 − Here, the main field to define is the directory for your backup. Ensure it’s on
another drive which is different from the drive where your Jenkins instance is setup. Click
on the Save button.
Step 6 − Click on the ‘Backup Hudson configuration’ from the Backup manager screen to
initiate the backup.
The next screen will show the status of the backup
To recover from a backup, go to the Backup Manager screen, click on Restore Hudson
configuration.
The list of backup’s will be shown, click on the appropriate one to click on Launch Restore
to begin the restoration of the backup.
Jenkins - Remote Testing
Web tests such as selenium tests can be run on remote slave machines via the master slave
and selenium suite plugin installation. The following steps show how to run remote tests
using this configuration.
Step 1 − Ensure your master slave configuration is in place. Go to your master Jenkins
server. Go to Manage Jenkins → Manage Nodes.
In our node list, the DXBMEM30 label is the slave machine. In this example, both the
master and slave machines are windows machines.
Step 4 − Now go to your slave machine and from there, open a browser instance to your
Jenkins master instance. Then go to Manage Jenkins → Manage Nodes. Go to DXBMEM30
and click on
Step 5 − Click on the DXBMEM30 instance.
Step 6 − Scroll down and you will see the Launch option which is the option to Start ‘Java
Web Start’
Step 7 − You will be presented with a Security Warning. Click on the Acceptance checkbox
and click on run.
You will now see a Jenkins Slave window opened and now connected.
Step 8 − Configuring your tests to run on the slave. Here, you have to ensure that the job
being created is meant specifically to only run the selenium tests.
In the job configuration, ensure the option ‘Restrict where this project can be run’ is selected
and in the Label expression put the name of the slave node.
Step 9 − Ensure the selenium part of your job is configured. You have to ensure that the
Sample.html file and the selenium-server.jar file is also present on the slave machine.
Once you have followed all of the above steps, and click on Build, this project will run the
Selenium test on the slave machine as expected
Thank you for Viewing, Hope this Jenkins hands on Tour will make you learn some basic
Information about the work flow of Jenkins and real time experience.
Senthilkumar.Sivakumar