Jenkins

0 Comments

 

Jenkins

  • Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and deploying software.

  • Jenkins is a powerful application that allows continuous integration and continuous delivery of projects, regardless of the platform you are working on.

  • Jenkins helps to automate the non-human part of software development process and facilitating technical aspects of continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.

 

Note:-Continuous Integration is a development practice that requires developers to integrate code into a shared repository at regular intervals. This concept was meant to remove the problem of finding later occurrence of issues in the build lifecycle. Continuous integration requires the developers to have frequent builds. The common practice is that whenever a code commit occurs, a build should be triggered.

 

In a nutshell, Jenkins is the leading open-source automation server. Built with Java, it provides over 1000 plugins to support automating virtually anything, so that humans can actually spend their time doing things machines cannot.

 

What and When jenkins ?

 

Use Jenkins to automate your development workflow so you can focus on work that matters most. Jenkins is commonly used for:

  • Building projects

  • Running tests to detect bugs and other issues as soon as they are introduced

  • Static code analysis

  • Deployment

Execute repetitive tasks, save time, and optimize your development process with Jenkins.

System Requirements

 

JDK

JDK 1.5 or above

Memory

2 GB RAM (recommended)

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.

Operating System Version

Jenkins can be installed on Windows, Ubuntu/Debian, Red Hat/Fedora/CentOS, Mac OS X, openSUSE, FReeBSD, OpenBSD, Gentoo.

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).

 

Let’s Download

The official website of jenkins is https://jenkins.io/index.html .

  1. Click on the above link.

2. 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.

3. Click the link “Older but stable version” to download the Jenkins war file.

4.open the command prompt and write the command D:\>Java –jar Jenkins.war

After the command is run, various tasks will run, one of which is the extraction of the war file which is done by an embedded webserver called winstone.

D:\>Java –jar Jenkins.war
Running from: D:\jenkins.war
Webroot: $user.home/ .jenkins
Sep 29, 2015 4:10:46 PM winstone.Logger logInternal
INFO: Beginning extraction from war file

Once the processing is complete without major errors, the following line will come in the output of the command prompt.

INFO: Jenkins is fully up and running

5. It’s time to access the jenkins,one can access Jenkins from the link − http://localhost:8080

It will navigate to the jenkins dashboard.



 

Binaries:-

 

Configuration of jenkins :-

We have 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.

Jenkins Home Directory

Jenkins needs some disk space to perform builds and keep archives. One can check this location from the configuration screen of Jenkins. By default, this is set to ~/.jenkins, and this location will initially be stored within your user profile location. In a proper environment, you need to change this location to an adequate location to store all relevant builds and archives. Once can do this in the following ways

  • Set "JENKINS_HOME" environment variable to the new home directory before launching the servlet container.

  • Set "JENKINS_HOME" system property to the servlet container.

  • Set JNDI environment entry "JENKINS_HOME" to the new directory.

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:- Set Environmental variable JENKINS_HOME to you’re the location you desire. As an example you can set it to E:\Apps\Jenkins

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.

SetUp build jobs ?

we will create a job in Jenkins which picks up a simple HelloWorld application, builds and runs the java program.

Step 1 − Go to the Jenkins dashboard and Click on New Item

Step 2 − In the next screen, enter the Item name, in this case we have named it Helloworld. 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.

source code will come here

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.

source code will come here

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

source code will come here

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.

Comments

WRITE A COMMENT