Getting Started with Jenkins

Sainadh
5 min readJun 7, 2021

From this blog, you will learn about what is Jenkins, CI/CD pipeline, how it works, Jenkins’s installation and setup using container image, and a real-world use case.

Prerequisites: -

  • Basic understanding of Maven, Containers and dockers for the practical purpose.

Jenkins

Jenkins is an open-source tool for building, integration, and automation on any project.

It is easy to use and understand and supports building pipelines using Groovy language.

Features of Jenkins

  • Easy Installation and Setting up the environment.
  • Easy to configure with other applications such as Git, Kubernetes, Cloud Environments …etc.
  • Can Integrate with other technologies and tools using plugins.
  • Can create a cluster to distribute the work on multiple nodes also known as Dynamic Provisioning.
  • It can be used for continuous integration and continuous deployment.

Jenkins is supported by RedHat, AWS, GitHub and many more.

If you want to do anything, use need to install a plugin.

Jenkins can be implemented using Web UI, Command Line Interface, and API’s.

Terminology

Job → It indicates a project.

Configure → It helps you to integrate Jenkins with other platforms and services.

Build → It runs or execute a Job.

Agent → A Dynamic Provisioner which is used to run the jobs, it can be any virtual machine or a container.

Pipeline → A user created model which executes multiple Jobs to provide continuous delivery.

Stage → It is a part of pipeline and like a job.

Plugin → It expands the capability of Jenkins and can be downloaded from Jenkins Web UI.

Trigger → A criteria for triggering a new pipeline or a build.

Downstream → A configured pipeline which is triggered by another pipeline or Job build process.

Upstream → A configured pipeline which triggers another pipeline as part of build process.

Continuous Integration and Continuous Deployment

Let’s investigate a developer role.

They usually code for a product or a service and push the code into Code Repository (Example Git), the team working on deployment takes the code and implement some test cases, after successful executions the code is taken by operations to deploy. In this scenario there are multiple layers of employees working together to put the code into production and it is a reputative process and continuous every week or a day. And the application is being monitored by someone daily.

The typical pipeline: -

Code → Repository → Build → Test → Deploy → Monitor

As most of the companies are using Agile methodology, it is very much hard to deploy the features fast and efficient manner.

There comes the use of Continuous Integration where the features developed by developer will be integrated to the existing code continuously, build the code and test as fast as possible.

After successful testing, the code is sent for deployment and in deploying the application there are multiple strategies. As companies are focusing on adding multiple features and to grow revenue there is not much time for testing in house on every possibility, so they release the latest version to some people, based on their feedback they fix the bugs and release it to everyone. This process is known as continuous deployment.

This is a continuous process, so there comes the use of Jenkins.

Installation of Jenkins using Containers

You may get a doubt that why to use the container technology to download and use Jenkins?

Container is a growing field, and everyone is transforming to use the container technology and to use it you must download Docker (available for most of the OS types).

Docker is like virtual machines and their architecture is hugely different.

docker pull jenkins/jenkins:latest

After installing run the Jenkins container as

docker run -itd --name -p 8080:8080 myjenkins jenkins/jenkins:latest

You can find the administrative password (it is only used once)

docker logs myjenkins

Now you can go to your browser and type 127.0.0.1:8080

After entering the administrative password click on Install Required Plugins.

Do install any plugins as it takes lot of time.

Setup the user in Manage Jenkins before closing the window

From next time onwards

For stopping the container → docker stop myjenkins

For starting the container → docker start myjenkins

If you want to do anything inside the container → docker exec -it myjenkins bash

In my upcoming blogs I will explain real time implementation of Jenkins Pipeline

Real World use case of Jenkins

Jenkins can be used by the companies which are using the programming languages to be compiled like Java, C, C++ …etc. For gaining better results.

Because the code is to be compiled and produce an artifact for deploying.

I will show a small practical.

Where you take the Java code from GitHub and then use Maven to build, test and create an artifact, we publish the artifact to the docker hub and then to the Kubernetes Cluster.

GitHub → MVN → Build Artifact → Build Docker Image → Publish to Docker Hub

Plugins: - To install plugins from Dashboard go to Manage Jenkins and then Plugin Manager

Required plugins to complete the process.

  • GitHub plugin
  • Docker plugin
  • Maven Integration
  • Cloud Bees Docker Build and Publish plugin

Maven is helps us to automate the build process of the software and an independent tool. Package manager for Java. It is built in Java.

Maven has its own repository where lots of modules are stored. It contains a pom.xml file, which contains all the modules with dependencies required to run the software.

# Download the file 
$ curl https://mirrors.estointernet.in/apache/maven/maven-3/3.8.1/source/apache-maven-3.8.1-src.tar.gz --output=maven.tar.gz
# Commands to install and setup maven$ tar -xvzf maven.tar.gz# ENV
$ export MAVEN_HOME=/<MVN_folder_path>

After that Goto docker config file

# In the file /usr/lib/systemd/system/docker.service
# In the line Exec Start at the end add
-H tcp://0.0.0.0:2376

Configure Maven in Jenkins

From Dashboard go to Manage Jenkins to Global tool configuration and then to maven section and path to the Maven folder.

Maven Configuration

Configure Docker to Jenkins

From Dashboard go to Manage Jenkins and Configure Clouds

Add the docker IP with port number

Docker Cloud configuring

In the dashboard create a new item with freestyle project then configure the steps to implement.

Github url :-https://github.com/Sainadh086/simple-java-maven-app.git

adding GitHub URL

Inside Build add the Maven commands to run and select the Maven path and add docker hub credentials.

In Build add maven and Docker

Finally run the build.

Now you can go to the docker hub and check the repository for the published image.

Conclusion

Discussed about Jenkins, CI/CD, docker and a small practical to publish the container images to docker hub from GitHub code.

Hope you liked the blog, and comment below if you have any doubts.

--

--

Sainadh

Devops and automation export, explorer, opensource enthusiast, follow for more content related to devops and easy way to do the things.