Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

Building a Spring Boot Application in Jenkins

Author: Patanjali Kumar
by Patanjali Kumar
Posted: Aug 17, 2020

Spring Boot is an open-source Java-based framework. In this project, we will be seeing how we can build our Spring Boot maven based Java project in Jenkins using CI/CD pipeline.

Pre-requisites

Jenkins should be installed in server : http://{ip}:{port}

The remote git repository with spring boot source code.

Building a sample Java Program in Jenkins using GIT

How to create New Job

To build this project using Pipeline, after installing Pipeline plugin, you please select the New Item menu in the Jenkins homepage to create a new Jenkins job.

Pipeline Section

Jenkins Pipeline (or simply "Pipeline") is a suite of plugins that supports implementing and integrating continuous delivery pipelines into Jenkins.

A continuous delivery pipeline is an automated expression of your process for getting software from version control right through to your users and customers.

Jenkins Pipeline provides an extensible set of tools for modelling simple-to-complex delivery pipelines "as code". The definition of a Jenkins Pipeline is typically written into a text file (called a Jenkinsfile) which in turn is checked into a project’s source control repository.

Why do we need Jenkins Pipeline?

Let’s say you are developing an application that you want to build, test, and deploy. Therefore you need three jobs for building, testing, and deploying, respectively. So after creating three jobs and chaining them into a sequence, the build plugin will run them as a pipeline job.

There are two types of Jenkins Pipeline code:

  1. Declarative Pipeline
  2. Scripted Pipeline

Declarative Pipeline Blocks

The following is a simple demonstration of building a pipeline to run multiple stages, each performing a specific task.

  1. The Pipeline block
  2. Agent block
  3. Option block
  4. Tools block
  5. Environment block

Let’s say you are developing an application that you want to build, test, and deploy. Therefore you need three jobs for building, testing, and deploying, respectively. So after creating three jobs and chaining them into a sequence, the build plugin will run them as a pipeline job.

Create a Jenkins CI/CD pipeline to automatically build changes from GIT Repo.

The above process is quite simple to implement for the small application but when you have many jobs with several processes, such as, build, unit test, integration test, pre-deploy, deploy, post-deploy, etc., will have huge maintenance cost and complexities. To overcome such issues Jenkins Pipeline Project comes to rescue.

The key feature of this pipeline is to define the entire deployment flow through code in a file called Jenkinsfile. A Jenkinsfile is a text file that stores the entire workflow as code and it can be checked into a repository system.

In this module, we will focus only on the declarative syntax as it is an advanced version of the scripted pipeline with extensible features. It is recommended using the declarative pipeline approach for all your Jenkins use cases. There are a lot of features and benefits you will get from the declarative pipeline approach.

By going through this project, you will understand how getting Jenkins running and building a Spring Boot project can be quite straightforward. Obviously, in a proper setup, you won’t want to be running Jenkins on your local machine, as you’ll need high availability and most likely access by other team members. If you’re using AWS consider running Jenkins in an ECS or EKS cluster.

The project can be explained clearly in the below steps.

  1. Introduction
  2. Create New Job
  3. Pipeline section
  4. Types of Pipeline
  5. Declarative Pipeline Blocks
  6. Jenkins file
  7. Output
  8. Conclusion
  9. Module Test
SkillPractical Java Learning path, DevOps Learning path give a structure to training programs. A sequenced and structured learning route has many benefits. This DevOps learning path is designed for individuals who want to learn how to use the most common DevOps patterns to develop, deploy, and maintain applications in the AWS Cloud. Build technical skills as you progress along the path toward AWS Certification.

About the Author

I am an Android developer. I have a 2 years of experience in IT industry. I worked on java also and have good experience on it.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Patanjali Kumar

Patanjali Kumar

Member since: Apr 14, 2020
Published articles: 3

Related Articles