Skip to main content

Creating a Jenkins Pipeline for Spring Boot application

Download, install, and run Jenkins

Download the latest stable version of Jenkins (2.361.3 LTS) - Generic Java package (.war).

Run the downloaded .war file with the following commands:

java -jar jenkins.war

It will run Jenkins as a "java" web application.

In order to access the Jenkins app, navigate to http://0.0.0.0:8080/.

An auto created admin "user" and "password" can be found from the output logs as well as from the file located at: /Users/nkchauhan003/.jenkins/secrets/initialAdminPassword.

Click on "Install suggested plugins".

Once plugins are installed, on the next screen, create an admin user. From now on, this username and password will be used to login instead of the default one.

Now we have a fresh installation of Jenkins ready to be used.

Let's create a "pipeline" following a more imperative programming model built with "Groovy".

To start using pipelines, we have to install the Pipeline plugin" that allows composing simple and complex automation.

We can also install the Pipeline Stage View plugin" to see all the stages we've configured.

We also need to install - JUnit plugin - to create and run the pipeline described in the next section.

In order to install a plugin, go to "Dashboard" > "Manage Jenkins" > "Manage Plugins".


Create pipeline for Spring BOOT project

In this demo, we will create a Jenkins pipeline that clones a spring-boot project from Git Hub, builds it, runs several tests, and then deploys the application.

Let's first create a new Jenkins job ("Dashboard" > "Create a job") selecting "Pipeline" as the type, as shown in the image below:

Select "Pipeline" from the "Configuration" menu on the top-left corner of the page.

Select "Pipeline script from SCM" from the dropdown and check "Lightweight Checkout."

Fill in "Repository URL," "Credentials," "Branches to build," and also check the name of the "Script Path." This file name, i.e., "Jenkinsfile," should be the same as the Jenkins file placed in the root folder of the project.

Jenkinsfile

Create a "Jenkinsfile" in the root directory of the Spring Boot application with the below content:

Here, we are all done setting up a Jenkins pipeline for a Spring Boot project. Let's go to "Dashboard" > "Jenkins Demo" and run "Build Now."


Comments

Popular posts from this blog

Deploying Spring Boot microservices on Kubernetes Cluster

This article guides you through the deployment of two Spring Boot microservices, namely "order-service" and "inventory-service," on Kubernetes using "MiniKube" . We will establish communication between them, with "order-service" making calls to an endpoint in "inventory-service." Additionally, we will configure "order-service" to be accessible from the local machine's browser . 1) Create Spring Boot microservices The Spring Boot microservices, "order-service" and "inventory-service," have been developed and can be found in this GitHub repository. If you are interested in learning more about creating Spring Boot REST microservices, please refer to this or this (Reactive) link. 2) Build Docker Images The Docker images for both "order-service" and "inventory-service" have already been generated and deployed on DockerHub, as shown below. codeburps/order-service cod...

Circuit Breaker Pattern with Resilience4J in a Spring Boot Application

Read Also: Spring Cloud Circuit Breaker + Resilience4j Resilience4j is a lightweight fault tolerance library that draws inspiration from Netflix Hystrix but is specifically crafted for functional programming. The library offers higher-order functions, known as decorators , designed to augment any functional interface, lambda expression, or method reference with features such as Circuit Breaker, Rate Limiter, Retry, or Bulkhead . These functionalities can be seamlessly integrated within a project, class, or even applied to a single method. It's possible to layer multiple decorators on any functional interface, lambda expression, or method reference, allowing for versatile and customizable fault tolerance. While numerous annotation-based implementations exist online, this article focuses solely on the reactive approach using router predicates and router functions . How Circuit Breaker Pattern works? In general, a circuit breaker functions as an automatic electrical s...

How to create a basic Spring 6 project using Maven

Below is a step-by-step guide to creating a basic Spring project using Maven. 1) Create a Maven Project Use the following Maven command to create a new Maven project. mvn archetype:generate -DgroupId=com.tb -DartifactId=spring-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 2) Import in IntelliJ IDEA If you haven't already, open IntelliJ IDEA on your system. Go to "File" > "New" > "Project from Existing Sources..." . In the file dialog, navigate to the directory where your Maven project is located. Select the pom.xml file within the project directory and click "Open." 3) Update pom.xml In total, the application requires the below-mentioned dependencies: 4) Create Spring Configuration Create a Java configuration class that uses annotations to define your Spring beans and their dependencies. This class should be annotated with @Configuration . 5) Create the Main Application C...