Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Jenkins one-click packaging how to deploy SpringBoot applications

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you Jenkins one-click packaging how to deploy SpringBoot applications, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

Introduction to Jenkins

Jenkins is a leader in open source CI&CD software, providing more than 1000 plug-ins to support build, deployment, automation, and meet the needs of any project. We can use Jenkins to build and deploy our project, such as getting code from our code repository, packaging our code into executable files, and then running our project through a remote ssh tool execution script.

Installation and configuration of Jenkins installation in Docker environment

Download the Docker image of Jenkins:

Docker pull jenkins/jenkins:lts

Run Jenkins in the Docker container:

Configuration of docker run-p 8080 root 8080-p 50000 root 5000-- name jenkins\-u root\-v / mydata/jenkins_home:/var/jenkins_home\-d jenkins/jenkins:ltsJenkins

Log in to Jenkins by visiting this address after running successfully. Enter the administrator password for the first login: http://192.168.6.132:8080/

To log in with an administrator password, you can obtain the administrative password from the container startup log using the following command:

Docker logs jenkins

Get the administrator password from the log:

Choose to install the plug-in. Here we install the recommended plug-in directly:

Enter the plug-in installation interface and wait for the plug-in to be installed online:

After the installation is complete, create an administrator account:

Configure the instance to configure the URL of Jenkins:

Click system Management-> plug-in Management to install some custom plug-ins:

Ensure that the following plug-ins are installed correctly:

Plug-in for managing permissions based on role: Role-based Authorization Strategy

Plug-in for remote use of ssh: SSH plugin

Configure global tools through system Administration-> Global tool configuration, such as maven configuration:

Add the installation configuration of maven:

Add the global ssh configuration to system Administration-> system configuration so that Jenkins can execute remote linux scripts using ssh:

Role rights management

We can use the role management plug-in of Jenkins to manage Jenkins users. For example, we can give all permissions to administrators, operation and maintenance staff to execute tasks, and other personnel only to view.

Enable role-based rights management in system Administration-> Global Security configuration:

Enter the system Management-> Manage and Assign Roles interface:

Add the relationship between roles and permissions:

Assign roles to users:

Package deployment of SpringBoot applications

Here we use the mall-tiny-jenkins module code from the mall-learning project to demonstrate how to make Jenkins package and deploy SpringBoot applications with one click.

Upload the code to the Git repository

First, we need to install Gitlab (of course, you can also use Github or Gitee), and then upload the code in mall-tiny-jenkins to Gitlab. For the use of Gitlab, please refer to: build your own Git warehouse in 10 minutes.

Mall-tiny-jenkins project source code address: https://github.com/macrozheng/mall-learning/tree/master/mall-tiny-jenkins

After uploading, the display effect in Gitlab is as follows:

One thing to note is to change the dockerHost address in pom.xml to your own Docker image repository address:

Execute script preparation

Upload the mall-tiny-jenkins.sh script file to the / mydata/sh directory with the following content:

#! / usr/bin/env bashapp_name='mall-tiny-jenkins'docker stop ${app_name} echo'- stop container----'docker rm ${app_name} echo'- rm container----'docker run-p 8088 app_name 8088-- name ${app_name}\-- link mysql:db\-v / etc/localtime:/etc/localtime\-v / mydata/app/$ {app_name} / logs:/var/logs\-d Mall-tiny/$ {app_name}: 1.0-SNAPSHOTecho'- start container----'

Add executable permissions to the .sh script:

Chmod + x. / mall-tiny-jenkins.sh

The .sh script under windows is uploaded to linux, and the file format needs to be modified, otherwise it cannot be executed because of the existence of a special format:

# use the vim editor to modify the vi mall-tiny-jenkins.sh# viewing file format. The default file format uploaded by windows is dos:set ff#. Modify the file format to unix:set ff=unix# and exit: wq

Execute the .sh script for testing, but you don't have to:

. / mall-tiny-jenkins.sh creates an execution task in Jenkins

First, we need to create a new task:

After setting the task name, choose to build a free-style software project:

Then add our git warehouse address: http://192.168.6.132:1080/macrozheng/mall-tiny-jenkins to the source code management

At this point, you need to add a credential, that is, the account password of our git repository:

Select the credential after filling in, and then you can connect to the git warehouse normally.

After that, we need to add a build and choose to call the top-level maven target. This build is mainly used to package our source code into a Docker image and upload it to our Docker image repository:

Select our version of maven, then set the maven command and specify the location of the pom file:

Then add a build that executes the remote shell script to execute the .sh script that starts the Docker container after our image is packaged:

The shell command that needs to be set and executed is as follows: / mydata/sh/mall-tiny-jenkins.sh

Then click Save, and our task is created. In the task list, we can click run to execute the task.

We can view the execution of the entire task through the console output:

After running successfully, visit this address to view the API document: http://192.168.6.132:8088/swagger-ui.html

The above is all the contents of the article "how to deploy SpringBoot applications with one click of Jenkins". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report