Creating a Jenkins Pipeline for Spring Boot application

  • 4.7/5
  • 5611
  • Jul 20, 2024

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."

Index
How to Implement PostgreSQL Full-Text Search with Spring Boot

15 min

Spring's transaction management with the @Transactional annotation

9 min

Spring Boot Rest APIs with PostgreSQL (Spring Boot + Rest APIs)

15 min

Caching in Spring Boot (@Cacheable, @CacheEvict & @CachePut)

21 min

Declarative REST Client in Spring Boot (Spring 6 HTTP Interface)

13 min

Circuit Breaker in Spring Boot (Spring Cloud Circuit Breaker + Resilience4j)

12 min

Handling Concurrent Service Calls in a Spring Boot Application: Asynchronous vs. Reactive Approaches

11 min

Profiling a Spring Boot application with Pyroscope

7 min

Service discovery in Spring Boot (Spring Cloud + Netflix Eureka)

9 min

Dockerize Spring Boot app and Push image to DockerHub (Spring Boot + DockerHub)

4 min

Creating a Jenkins Pipeline for Spring Boot application

2 min

Monitoring Microservices (Spring Boot + Micrometer + Prometheus + Grafana)

7 min

Edge Server Pattern in Microservices (Spring Cloud Gateway)

7 min

Circuit Breaker Pattern in Microservices (Spring BOOT + Resilience4j)

4 min

Spring Cloud config server setup with Git

8 min

Distributed Tracing in Microservices (Spring Cloud Sleuth + Zipkin)

9 min

Circuit Breaker Pattern with Resilience4J in a Spring Boot Application

24 min

Deploying Spring Boot microservices on Kubernetes Cluster

12 min

Reactive programming in Java with Project Reactor

50 min

Spring Reactive with PostgreSQL (Spring Boot WebFlux + PostgreSQL)

13 min

Spring Reactive, Thymeleaf Hello World (Spring Webflux + Thymeleaf + JS/CSS)

9 min

Problem JSON (application/problem+json) in Spring WebFlux

15 min

Spring Boot Login/Logout (Spring Security + MySql + Thymeleaf)

21 min

Securing Server-to-Server Communication with "Spring Boot" & "OAuth 2"

18 min

Integrating Elasticsearch with a Spring Boot and PostgreSQL application

16 min

Sending Emails in Spring Boot via SMTP

7 min

How to create a basic Spring 6 project using Maven

5 min

Spring Boot, Thymeleaf Hello World (Spring Boot + Thymeleaf + JS/CSS)

9 min