Jenkins for Continuous Integration

Reading Time: 4 minutes

Jenkins is not a new term to almost all of us. It’s a continuous integration/continuous deployment server. Before starting off with Jenkins, let’s first understand what Continuous Integration is.

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

By integrating regularly, you can detect errors quickly, and locate them more easily.

continuous integration cycle

Need for Continuous Integration

Screenshot from 2018-01-18 15-21-52

How does Jenkins help us?

The job of Jenkins is to execute a predefined list of steps eg. to compile the source code, execute test cases, build a Jar from the resulting classes. If any of the steps fail in its execution, it’ll terminate the build process. Whatever be the status of the build whether it is failed or passed, Jenkins will notify us if we ask for it. Triggers can be event-based or time-based. Say, for example, build will be made after every 2 hours or whenever a new code change is committed.

Installing Jenkins

Installing Jenkins is as easy as falling off a log. Just follow these simple steps:

  1. Download Jenkins.
  2. Got to the folder containing the jenkins.war file.
  3. Open the terminal and run this command:

                      java -jar jenkins.war

This will deploy Jenkins into the local JVM. Now your Jenkins is up and running.

Or,

  1. Install tomcat server.
  2. Navigate to the webapps folder and copy paste your jenkins.war file into this folder.
  3. As soon as tomcat starts this jenkins file will get deployed on 8080 [local].

You can now go to Jenkins dashboard – localhost:8080

Now, we are all set to make our very first build.

Follow these steps:

STEP 1: Here, you can see various options on the left side. Select New Item.

 

STEP 2: Now you see a new page.

first_jenkins

Here you can select the type of your project. I am selecting Freestyle project for this demo. Since Freestyle is the most configurable and flexible option. And also that it is easy to set up.

STEP 3:  Now go to the Source Code Management tab. Select Git for your project in git. Provide the Repository URL.

 

jenkins_777

 

 

 

STEP 4: Go to Build tab. Select Invoke top-level Maven targets.

j5

Maven has a build cycle. Build cycle has multiple build phases like validating the code, compilation, testing, packaging in jars, verify, install any package if you want and then you can deploy it in the production environment for release.

In the Goals tab, you give the job you want to execute. In my case, I just want to compile it. So I’ll write compile. This will trigger the compile build phase of maven.

 

jenkins_blog

That’s it. Apply and Save it.

STEP 5: Now on the left-hand side, click on Build now to trigger the build.

j77

To see the console build output, you can click on that build and see the console output.

j55

final

Now go to the Jenkins dashboard. You can see the result of this build. Blue ball depicts that it has been successfully compiled.

As simple as it is depicted above. You have successfully made your first build using Jenkins. I hope it was helpful. 🙂

References:

  1. https://jenkins.io/doc/
  2. https://www.edureka.co/blog/what-is-jenkins

 


knoldus-advt-sticker


Written by 

Tech Enthusiast

2 thoughts on “Jenkins for Continuous Integration3 min read

Comments are closed.

Discover more from Knoldus Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading