Jenkins Tutorial: A Comprehensive Guide

Continuous integration is a significant step in the DevOps lifecycle. It makes the development, testing, and deployment of applications easier and faster. Of all the continuous integration tools, Jenkins is probably one of the most popular, and you can’t be an effective part of the DevOps revolution if you don’t know this tool. If you’re wondering why Jenkins has gained so much traction within the DevOps community, the following tutorial should clear things up.

Jenkins started as a hobby for a developer at Sun Microsystems in the early 2000s. However, Jenkins soon evolved into an extremely robust and powerful automation service that was released under an MIT license and is now adopted all over. The Jenkins developer community is vast and supported by different kinds of plugins. These plugins are so crucial for Jenkins because they allow the user to connect it to just about everything.

This tutorial will help you gain a fundamental understanding of Jenkins, including prerequisites for developers, installation and configuration, creating new users and managing permissions, integrating GitHub with Jenkins, deploying Maven-based web apps to a Tomcat server, and much more. We’ll also provide an overview of how you can upgrade your DevOps skills to take advantage of Jenkins and give your career a significant boost.


Learn the basics of Devops

Watch the beginner level video lessons for FREEGet Access Now
Learn the basics of Devops

What is Jenkins? 

Jenkins is an automation tool that is open-sourced and written in Java. It has plugins built for continuous integration. You can use Jenkins to build your software projects and test them continuously, allowing developers to integrate any changes in their projects easily. It also allows you to consistently deliver your software since it’s integrated with so many testing and deployment technologies. It will enable organizations to accelerate their software development process with automation.

Some of the main advantages of Jenkins include the following: 

  • The tool is open source and has robust community support
  • Jenkins is very easy to install
  • There are more than 1,000 plugins that make your work easier
  • Jenkins is free for all users
  • It is portable to most platforms since it’s built with Java

Prerequisites and Installation

Web applications written in Java can be run/installed in three ways:

Jenkins Installation

The Jenkins web application can be installed in any system, but the most common are Windows and Linux. There are three ways in which it can be run or installed.

  1. In a generic war file
  2. On Windows or Linux devices; if you have Windows, download an MSI installer (it should be specific to Jenkins)
  3. On any Java-based web server, such as Apache Tomcat (this is one of the older ways of running Jenkins)

Download these if they’re not already present in your system: 

There are some prerequisites to install Jenkins

Jenkins Installation

 The following are required before the user can install Jenkins:

  • JDK 1.7 or JDK 1.8. JDK stands for Java development kit
  • 2GB of RAM
  • Set environment variable JAVA_HOME to point to the JDK base directory

Search for “Download Jenkins” on your browser. Different flavors of Jenkins are available for the user to download. We recommend you download the Windows MSI installer.

You should be aware of the Jenkins Home variable.

Learn server automation, continuous integration, distributed system in Jenkins with the CI/CD Pipelines with Jenkins Certification Training Course. Enroll now!

Jenkins Root folder

All of the configuration data, project workspace, and jobs of Jenkins are stored in a root (or parent) folder:

  • C:\Program Files (x86)\Jenkins
  • C:\User_Home_DIR\Jenkins

Set the Jenkins Home Variable if you want to set up a backup before you even begin the installation. Start the installation by running the downloaded MSI installer; there will be a few checks to complete. Jenkins will launch on port 8080 by default. You should open the localhost 8080 and type the hash key.

Customize Jenkins

The Customize Jenkins screen appears next. Here, you will get two options:

  1. Install suggested plugins
  2. Select plugins to install

Select “Install suggested plugins,” as Jenkins recommends. You will get these plugins as you download Jenkins. A lot of bandwidth is required during this installation process, and some of these plugins will fail if you don’t have the required bandwidth. Once the plugins are downloaded, you can move on to the next step.

Create First Admin User

  • Create a username
  • Enter a password you can remember
  • Add your full name and email address
  • Click on Save and Finish 

This completes the Jenkins installation.

Jenkins Typical Configurations

Let us discuss some minimal configurations of Jenkins required for a first-time installation. The following steps will have to be done under “Manage Jenkins.”

Jenkins Configuration

1. Go to Configure System, where you can put in the configuration for Jenkins.

Jenkins Configuration

Look out for the Home directory, where everything related to Jenkins is stored. In System Message, you can add a message for the system. The number of executors is important because it lets Jenkins know how many jobs or threats can be run in a particular instance (two is enough for a single-core system). You can add an email address in the SMTP server if you want to send out emails through Jenkins. If you use Gmail, then you need to lower your security level on the email account.

2. The Global Tool Configuration is also important.

Jenkins Configuration

You need to add the tools required for building the appropriate code. If you want Jenkins to run a Java code, for example, you need to install JDK and to use Git, and you, you need to install Git and set the path. If you don’t do this configuration, Jenkins will not be able to find these tools and run them.

3. Configure Global Security.

Jenkins Configuration

By default, the security access control will be set to Jenkins’ user database. If you are in a given organization, you need to configure it specifically. For instance, the LDAP server will have to be specified.

After completing these configurations, you can move on to creating new jobs.

1. Go to New Item and add a name like First_Job.

Jenkins Configuration

Opt for an option like Freestyle Project and press Ok.

2. You can see tabs for General, Source Code Management, Build Triggers, Build, and Post-Build actions. You can see more options for adding more plugins.

Jenkins Configuration

3. Under General, you can put up a simple job at first and others later as needed. Add a description and any Triggers or Source Code, as required. You can build your job (and add more jobs) from there. As you add jobs and configure them with more detail, you’ll see how powerful the automation server is.

4. After you put up jobs, you need a way to control your Jenkins server. For this, you need to use a plugin called Role-based access plugin and create a few rules. There are global rules and project rules. Users can be assigned to these rules and thus controlled. You can select the role-based access plugin In the plugin manager if it’s already installed.

5. You can assign roles for users under Manage and Assign Roles.

Jenkins Configuration

The plugins are essential for this. You can select which permissions are given to a particular user under global roles. This allows the user to have limited access according to what you want.

Jenkins Configuration

Jenkins is popular for a variety of reasons, including the availability of numerous plugins created by other Jenkins users (most of which are free). When you search for Jenkins plugins, you will see a large index of great plugins from which to choose. These plugins are the heart of Jenkins, and you need them to connect Jenkins with any containers or toolsets. Plugins are required for any of the following:

● Maven and Java

● MS Build

● AWS or Amazon Web Services

● Docker

● GitHub

● SonarQube

All of these will work well because of the available plugins.

For instance, Jenkins can go to GitHub and pull a specific repository from there and bring it to your local system, compiling the repository and running the application. When you have integrated Jenkins successfully with GitHub for a Java application, you can build on top of it. 

Look for a Maven-based web application in your GitHub repository. Maven is a straightforward Java-based build tool that allows users to run various targets. Based on what goals you specify, Maven can compile and run tests. It can also build VAR files and deploy them to other servers and be used to develop and create a package from a particular web application. The index.jsp contains an HTML file that is part of the web application. 

If you want to connect Jenkins to a particular repository, you need two more things: 

  1. Maven (Jenkins will use the installed version) 
  2. Tomcat server

You should first download Maven and set up the configuration. For the Tomcat server, you’ll also need to make a few subtle changes in configurations according to what you need. 

The ports for both Maven and Tomcat should be different, or they will clash. 

You need to create a user on Tomcat and provide the user credentials to Jenkins, which will enable Jenkins to get into your Tomcat server and deploy the application. Your Tomcat server will soon be up and running with a few steps. You can then use Maven as a part of your job. 

Now, create a new job as a freestyle project. For source code management, you can select Git, copy the URL, and set the credentials.

Jenkins Configuration

You need to run some simple Maven targets. Run a Maven package that creates a war file.

Jenkins Configuration

Save and run it to make sure it connects well. Once it’s generated, you can see the location of the war file. 

You can grab the war file and deploy it into a Tomcat server, which requires a plugin because Tomcat has to be connected to the Jenkins server. Configure the plugin to pull up the war file and deploy it into the Tomcat server. You can add a post-build step and select “Deployment to a container.”

Jenkins Configuration

It will show up after the plugin is installed. You can configure further and run it after completing the required steps.

Distributed Build

In any development environment, you will find the Jenkins slave to be present in different operating systems, and they communicate with the Jenkins server (master) using the TCP/IP protocol. A code commit in the GitHub repository triggers continuous integration. The result of the operation is sent back to the Jenkins server (master).

We’ll now need to learn how to set up a slave, connect it, and delegate a job to it. There are many ways in which the client and server can communicate; here, we use the Java Network Launch Protocol (JNLP). To enable the JNLP port, click on Configure Global Security and scroll over to Agents.

Jenkins Configuration

Select Random and click on Save.

Under Manage Jenkins, select manage nodes. Currently, there is only one master node.

Jenkins Configuration

Provision a slave node by clicking on New Node. Provide a name, enable Permanent Agent, and click on Ok. Next, fill in the details regarding the node as shown and save it:

Jenkins Configuration

After provisioning, when you click on the new node (slave), a command line (launch code) appears along with agent.jar, which needs to be run on a different system. Download the agent.jar file and copy it to the other system; then run it using the launch code through the command prompt. This is how the agent gets connected. 

Delegating a Job to the Slave Node

To create a new task in Jenkins, enter the name ‘Delegate_Job’ and click on the Freestyle project. Head over to Build Environment and give the command as shown:

Echo “Delegate to Agent”

Click on SAVE and Apply.

Hone Your Skills with Jenkins and Give Your Career a Boost

There is a lot you can do with Jenkins, but it has a learning curve. If you’re thinking about adding this important tool to your skillset, consider enrolling in Simplilearn’s CI/CD Pipelines with Jenkins certification course. This course, employing Simpliearn’s unique Blended Learning learning approach, provides several hours of live, online, instructor-led learning and self-paced projects to get you career-ready upon completion. 

If your goal is to land a career in DevOps, you can enroll for the DevOps Engineer Master's Program. The program helps you gain expertise in the principles of continuous development and deployment, automation of configuration management, inter-team collaboration and IT service agility, using DevOps tools such as Git, Docker, Jenkins and more.

To learn more, check out the Simplilearn's video on Jenkins Tutorial.

Learn for free! Subscribe to our YouTube Channel & Be a Part of 400k+ Happy Learners Community.

”Get

About the Author

Avijeet BiswalAvijeet Biswal

Avijeet is a Senior Research Analyst at Simplilearn. Passionate about Data Analytics, Machine Learning, and Deep Learning, Avijeet is also interested in politics, cricket, and football.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.