Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]

In order to practice CI / CD, I set up Jenkins to generate Artifacts and deploy it to the application server.

The source code and server construction are described in this Preparation. If you want to automatically deploy to Tomacat server, refer to Tomcat application.

Job flow of Jenkins [^ 1]

  1. Check out the source code
  2. Build with Maven and output jar file
  3. Transfer the jar file to the JVM server
  4. Run the jar file

Check out the source code

Select Git from ** Manage source code **, and check out the Github repository prepared in the preparation section. [^ 2] For branch, specify * / master.

Run build with Maven and output jar file

Select ** Run Shell ** and run it with the ./mvnw command.

The build uses maven, but it runs in the Maven Wrapper included in the repository instead of the Mave task. Since there are two projects in the repository, I move the current directory to WebSpringBoot before executing it.

cd WebSpringBoot
./mvnw clean package

When you run Maven, web-spring-boot.jar will be generated in / WebSpringBoot / target.

Transfer the jar file to the JVM server

Select ** Run Shell **, SSH into the JVM server and place the generated Artifacts: web-spring-boot.jar. Also, make the transferred jar file full access (rwx) for the following reasons.

--Allow overwriting of files for continuous deployment. --Since it self-starts from the service of the JVM server [^ 3], it allows the execution of the file.

#Transfer the jar file from Jankins to the JVM server with SCP command
scp -i ~/.ssh/id_rsa WebSpringBoot/target/web-spring-boot.jar [email protected]:/var/jvm
#Grant execute permission
ssh -i ~/.ssh/id_rsa [email protected] sudo chmod 700 /var/jvm/web-spring-boot.jar

Run the jar file

Select ** Run Shell ** to SSH into the JVM server and restart the application service. ssh -i ~/.ssh/id_rsa [email protected] sudo systemctl restart app

If the Jenkins job execution is successful, you can check the application execution from the following URL. http://192.168.33.20:8080/

Build setting screen

image.png

reference

Installing Spring Boot Applications(from Spring Boot Reference) Spring Boot Reference Guide

[^ 1]: This time, I wanted to build and deploy by command execution, so I used the ** Shell execution ** task.

[^ 2]: This repository contains two Maven projects, ** WebSpringMvc ** for war and ** WebSpringBoot ** for jar. This time, we will use / WebSpringBoot.

[^ 3]: To make the jar executable, set the executable setting of spring-boot-maven-plugin to true

Recommended Posts

Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
Automatically deploy a Web application developed in Java using Jenkins [Preparation]
Automatically deploy Web applications developed in Java using Jenkins [Tomcat application]
Java beginner tried to make a simple web application using Spring Boot
Create a Spring Boot application using IntelliJ IDEA
Java tips-Create a Spring Boot project in Gradle
Deploy a Spring Boot application on Elastic Beanstalk
Sign in to a Spring Boot web application on the Microsoft ID platform
Create a portfolio app using Java and Spring Boot
[Spring Boot] Web application creation
CICS-Run Java application-(4) Spring Boot application
Sample web application that handles multiple databases in Spring Boot 1.5
Introducing Spring Boot2, a Java framework for web development (for beginners)
Spring Boot application development in Eclipse
Implement Spring Boot application in Gradle
Let's make a book management web application with Spring Boot part1
Let's make a book management web application with Spring Boot part3
[Java] Get data from DB using singleton service in Spring (Boot)
Let's make a book management web application with Spring Boot part2
Fitted in Spring Boot using a bean definition file named application.xml
ERRORCODE = -4471 occurs in Java application using Db2.
Create Java Spring Boot project in IntelliJ
Start web application development with Spring Boot
Deploy a Java web app on Heroku
Role of JSP in Web application [Java]
Run WEB application with Spring Boot + Thymeleaf
A story about a Spring Boot project written in Java that supports Kotlin
Deploy the WEB application by Spring Boot to Tomcat server as WAR
[Java] Deploy a web application created with Eclipse + Maven + Ontology on Heroku
I tried to make a talk application in Java using AI "A3RT"
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
Deploy Java application developed in IntelliJ IDEA environment to Alibaba Cloud ECS instance
Run a Spring Boot project in VS Code
How to display a web page in Java
[AWS] How to automatically deploy a Web application created with Rails 6 to ECR / ECS using CircleCI ① Preparation [Container deployment]
Let's create a super-simple web framework in Java
How to add a classpath in Spring Boot
I tried to clone a web application full of bugs with Spring Boot
Create a web api server with spring boot
CSRF countermeasure policy and implementation example in REST application using "Spring Boot" + "EXT JS"
[For beginners] Until building a Web application development environment using Java on Mac OS
A story that stumbled when deploying a web application created with Spring Boot to EC2
Try using OpenID Connect with Keycloak (Spring Boot application)
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
Automatically generate DDL using [jpa-schema-gradle-plugin] plugin in Spring × Gradle
[Introduction to Spring Boot] Submit a form using thymeleaf
Test field-injected class in Spring boot test without using Spring container
How to convert A to a and a to A using AND and OR in Java
Create a JAVA WEB application and try OMC APM
Spring Boot 2.3 Application Availability
Deploy a Java application developed locally with the Cloud Toolkit to an Alibaba Cloud ECS instance
Let's make a calculator application in Java ~ Display the application window
Web application development environment construction in Java (for inexperienced people)
Deploy Spring Boot applications to Heroku without using the Heroku CLI
The first WEB application with Spring Boot-Making a Pomodoro timer-
Deploy the application created by Spring Boot to Heroku (public) ②
How to call and use API in Java (Spring Boot)
Deploy the application created by Spring Boot to Heroku (public) ①
Get error information using DefaultErrorAttributes and ErrorAttributeOptions in Spring Boot 2.3
Try developing a containerized Java web application with Eclipse + Codewind
How to deploy Java application to Alibaba Cloud EDAS in Eclipse