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

How Jenkins automatically deploys SpringBoot projects

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how Jenkins automatically deploys SpringBoot projects. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Jenkins installation

Download jenkins installation package, maven installation package; open xftp to upload the installation package to the server; get maven image: enter maven's conf folder, vim open setting.xml file to add Ali cloud image; wq! Save exit.

Alimaven aliyun maven http://maven.aliyun.com/nexus/content/groups/public/ central

Configure the environment variable, open the / etc/profile file, and add the environment variable for maven; after adding, remember to execute source / etc/profile to make the environment variable take effect. Add the configuration as follows: change MAVEN_HOME to your own maven installation directory

MAVEN_HOME=/usr/local/maven3export MAVEN_HOMEexport PATH=$ {PATH}: ${MAVEN_HOME} / bin

Run mvn-v to verify that maven is installed successfully

Enter the jenkins installation location to execute: java-jar jenkins.war &; start; start unsuccessfully. If the port is occupied, you can use the following command to modify the port number and start. Generate a password after execution and write it down

Java-jar jenkins.war-ajp13Port=-1-httpPort=8081 &

If you cannot access jenkins;, check whether there is a security group that uses ports on Aliyun and the opening of pagodas. If you do not use pagodas, use the command to develop ports:

Firewall-cmd-zone=public-add-port=8081/tcp-permanent

Access the http:// server ip: Port number; the jenkins login page appears and log in using the password remembered in step 5.

2. Install the Jenkins plug-in

Select system management, plug-in management

To install the ssh plug-in, click the optional plug-in, search for the Publish Over SSH plug-in, and follow the Infrastructure plugin for Publish Over X plug-in before installing the Plublish Over SSH plug-in. Or report a mistake.

Search for gitee in the plug-in and install the plug-in.

Search the Jackson 2 API plug-in

Search Java JSON Web Token (JJWT) plugin, Javadoc Plugin plugin, JUnit Plugin

Search for the Maven Integration plugin plugin. If you can't find it, remove the plugin search behind it.

Search the Publish Over SSH;SSH Build Agents plugin;SSH Credentials Plugin;SSH plugin;SSH2 Easy Plugin plug-in

If there is a problem with the plug-in later, you can check which plug-ins are missing from Baidu and then continue to install them. 3. Jenkins setting credentials to select system management, click Manage Gredentials

Click Jenkins

Click Global credentials

3. Click to add credentials

Add server credentials and fill in the server login user name and password

Add gitee user credentials, fill in the gitee account username password, add gitee private token credentials, go to the gitee account to add private tokens, get private tokens and then add credentials.

4. Jenkins environment configuration 4.1, global configuration

Select Manage Jenkins system management, select Global Tool Configuration global tool configuration to enter some configuration environments of configuring java

Enter the configuration environment Maven and JDK and save

The Maven here selects the path of the maven downloaded from the server, and the JDK selects the server installation path. If the JDK installation path cannot be found, please see the server jdk installation location query steps here:

Cancel the automatic installation of jdk and select the installation address of jdk in the server

4.2. System configuration

Go back to select Manage Jenkins system management, select system configuration

Maven configuration

Jenkins URL configuration

Environment variable configuration

SSH configuration

Gitee configuration

Log in to the target publisher using a key

Enter the command: ssh-keygen-t rsa enter; something appears directly copy () the things pasted; enter; always enter until the graphics appear.

Go to the / root/.ssh folder and ls can view three things, a private key, a public key, and an authorized_keys file. Append the public key to the authorized_keys file using the command: cat id_rsa.pub > > / root/.ssh/authorized_keys; file.

Write the generated ssh path on Path to key on Public over SSH in the system configuration:: / root/.ssh/id_rsa

Select Confing System, configure the ssh service, and fill in the following information

If the following error occurs after clicking Test, check to see if the credentials are set:

5. Jenkins automatically deploys SpringBoot projects

Create a new springboot project, write a demo test to see if it can be run, then upload it to gitee to create a new tiem (New Task), create a new task in Jenkins, select to build a maven project, and then make sure

General sets up Gitee project links

Source code management, click Advanced at git, and fill + refs/heads/master:refs/remotes/origin/master + refs/pull/*/MERGE:refs/pull/*/MERGE into Refspec.

Build trigger, build environment

SSH remote hosts in system setup

To set up Pre Steps,Build,Build, click Advanced to expand and fill in the following information

Set up Post Steps

The shart.sh file is as follows:

/ root/www/javaweb/project/testJenkis/demo-0.0.1-SNAPSHOT.jar is the jar package that appears here after the project is compiled, and the jar command is concatenated with artifactId and version in the project's pom file.

/ root/www/javaweb/project/testJenkis/out.log is the location of the project's compiled log file.

#! / bin/bashsource / etc/profileexport JAVA_HOME PATH CLASSPATHJAVA_HOME=/usr/java/jdk1.8.0_121 # your own jdk path PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$CLASSPATHexport BUILD_ID=dontKillMeecho "= close the Java application =" PROCESS= `ps-ef | grep java | grep-v grep | grep / root/www/javaweb/project/testJenkis/demo-0.0.1-SNAPSHOT.jar | awk'{print $2} '`for I in $PROCESSdo echo "Kill the $1 process [$I]" kill-9$ idoneecho "= launch Java app =" nohup java-jar / root/www/javaweb/project/testJenkis/demo-0.0.1-SNAPSHOT.jar > / root/www/javaweb/project/testJenkis/out.log 2 > & 1 & echo $! > savePid.txtcat savePid.txtrm savePid.txt

Then authorize the start.sh file with the following command: 777 represents readable, writable and executable

Chmod-R 777 start.sh

Apply Save Task Settings Click to build now

You can select the console output to view the running results. If there is an error, see the prompt to modify it. If successful, you can access the interface path set in the project.

6. Encounter problems

1. Restart jenkins and forgot your login password

1. The cd / root/.jenkins/users command goes to the users folder to see if there is a user folder under the file, and find the admin folder

two。 Open the admin folder and find a config.xml file inside. Open the modified file and find the passwordhash. You can copy and save the original passwordhash first.

3. Then modify the content in passwordhash to the following and save the exit: `# jbcrypt:$2a$10 $MiIVR0rr/UhQBqT.bBq0QehTiQVqgNpUGyWW2nJObaVAM/ 2xSQdSq`

4. Then restart jenkins. If the restart fails, the port may be occupied. It is estimated that the previously started jenkins is still running, so you can check netstat-anp | grep 8081; whether the port is occupied or not, use the kill-9 process id to kill the process.

5. Then restart the jenkins command before: java-jar jenkins.war-ajp13Port=-1-httpPort=8081

6. Log in with a 123456 password to access jenkins.

7. Success

2. There is a problem installing the ssh plug-in.

Select Manage Plugins, optional plug-in

The following error occurred while downloading ssh

The reason for the failure is to install the following plug-ins first, and then the installation will not go wrong.

3. The following error occurred in the construction project:

Modify the build in the pom.xml file of the project to the following code: remember to upload to gitee, or modify pom directly in the project that was previously uploaded to gitee

Compile org.springframework.boot spring-boot-maven-plugin org.projectlombok lombok

4. Yellow appears after clicking build now. The error is as follows:

The problem is that you can't find the strat.sh. Take a closer look at the post-build operation of the configuration, be sure to create the shart.sh file in the root directory, and when configuring the path here, add / root/ instead of www directly, otherwise the above error will occur.

5. If the compilation is successful, but no jar file appears in the specified location on the server, check the out.log content discovery.

Then try to change the path of the specified jar location

Before modification:

After modification:

Jar is placed under www under the root directory, but there is no need to add root when configuring here. Only start.sh must be added with root, otherwise there will be an error.

Successfully solve the problem

Check that the port is also running.

Just check the browser.

7. Commands used

Enter maven-v; check if maven is installed on the server.

Java-version; to see if the server has a jdk environment

Mkdir maven; create folder

Tar-zxvf file name; extract folder

Whereis java; View the jdk installation directory

Lsof-iPlus 8080; check whether port 8080 is occupied

Kill-9 PID; kills a running process

Java jar jenkins.war-- ajp13Port=-2-- httpPost=8080 &; start the jenkins program

Chmod-R 777 start.sh; authorizes files and 777 is readable and writable

Pwd; displays the current directory

Vim file; open file, I: edit; esc: exit editing;: wq! Save exit

Thank you for reading! This is the end of the article on "how Jenkins automatically deploys the SpringBoot project". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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