当前位置:网站首页>Super details to teach you how to use Jenkins to realize automatic jar package deployment

Super details to teach you how to use Jenkins to realize automatic jar package deployment

2022-06-11 05:53:00 Endwas

Welcome to my blog , communication :https://endwas.cn

Here we will only demonstrate the deployment of a single project , If it is a distributed project or in KubeSphere Just change the traditional build project into a pipeline , Here we will simply implement a drop-down code ,maven pack , Package upload , restart jar Bag, etc .

jenkins Install to view another of my articles blog, It's used inside. docker install , Faster and more traditional tomcat+war perhaps yum A lot of holes are missing in the installation .

Be careful : The use of maven It's attached , download maven:maven3.5.4, So we need to docker Host installation maven, And configure environment variables .


1.jenkins Entry configuration

1. Get the initial password

open jenkins page , The default port is ip:8080 Local is localhost:8080;

 Insert picture description here

First Unlock jenkins, Go to through the server jenkins The container of

docker exec -it jenkins /bin/bash
[email protected]:/$ cat /var/jenkins_home/secrets/initialAdminPassword
a6f6d08fcc474178833001d1fc79be62

2. Install the default plug-in

Then install the default plug-in , If you know what plug-ins you need, you can also choose to install them .
If you don't know to install the default first , What to use and install later .

 Insert picture description here

3. Create administrator account

Then create the first account after installation

 Insert picture description here

4. The instance configuration

Just configure the instance with the default server address

 Insert picture description here
such jenkins The default configuration is fine , But the plug-in is still missing .

2. Installing a plug-in

1. Enter system management

 Insert picture description here

2. Click plug-in management

 Insert picture description here
These three configurations are most commonly used in system configuration , Remember that their entrance is just on the left, and the gear enters .

3. Install the required plug-ins

Choose an optional plug-in Search for what we need to install , If the search fails, confirm whether it has been installed .

 Insert picture description here
1️⃣ Publish over ssh:ssh Plug in for transferring files , Equivalent to what we usually use xftp, Used to upload files to the server .
2️⃣ Maven Integration plugin: Used for configuration maven Of , Used in jenkins Hit middle jar package .
3️⃣ Role-based Authorization Strategy: Used to control permissions , Administrators can be set up for different users 、 read 、 Write permissions .

Remember to restart after installation jenkins.

3. Configure the installed plug-ins

Return to system configuration

 Insert picture description here

1. To configure maven

In the previous article, I installed , I mounted a maven Folder , that maven The purpose of folders is to use in containers .
Then find a folder on the server and unzip it , Then mount to docker Use in .

Go to global tool configuration ->Maven
name: Random filling
MAVEN_HOME: Mount to docker In the path , Because I also packed a layer of folders, so my maven It's on the apache-maven-3.5.4/ Next
 Insert picture description here

To configure settings file . Similarly, find the folder settings Just fine
 Insert picture description here

2. To configure ssh

Go to the first... Of the system configuration , The system configuration
find publish over ssh
 Insert picture description here
Then click advanced to open the setting port + password

 Insert picture description here
Finally, test the connection , Tips success It can be connected ~

4. Create automated tasks

All the preparations are ready , Start creating Automated Deployment tasks .

  1. Pull the code .
  2. pack .
  3. Upload the corresponding server .
  4. restart jar package .

1. Pull the code

 Insert picture description here
 Insert picture description here
Be careful :git Address if ssh You need to configure public and private keys , For specific use, please see jenkins To configure git, Here, you can use the account and password to obtain

 Insert picture description here
git User name and password

 Insert picture description here

2. pack

 Insert picture description here

Be careful : The path here is the path under the working directory , We pull down the code ,pom.xml In the folder , So the configuration is pom.xml, If it is a micro service multi-layer folder, you need to specify
xxx Microservices /pom.xml

//  skip test It can also be used directly clean package
clean package -Dmaven.test.skip=true

3. hold jar Package upload server

 Insert picture description here

This is because I want to upload to the server , So I chose send files Options

 Insert picture description here
Let's focus on post steps Configuration of

  • name: Servers previously configured in the global configuration , Select the specific configuration .
  • Source files: stay jenkins Workspace pack after , Files to upload , Because our package will be produced in target/xxxxxx.jar, So we need to match it target/xxxx.jar
  • Remove prefix: If this is not configured , Then we will target Folder +jar Package upload to server , Because we just need to jar package , So configuration target/
  • exec command: After uploading the folder , stay The target server performs Script for , A script is a program restart , If you need a backup, you can do it in pre Step execution shell The backup script .
  • If the target server already has the same name jar package , It will cover .

Be careful : The reason why the script execution failed

  1. You need to go to the script location sh restart.sh.
  2. If the startup command fails to execute , stay sh with source /etc/profile.
cd /home/endwas/d
source /etc/profile
sh restart.sh

4. function

 Insert picture description here

ps: If the execution fails, click the version number , Check the log , Confirm which step failed

 Insert picture description here

summary

jenkins Automated Deployment , In addition, the visual interface is very helpful for operation and maintenance , The efficiency of test and front and rear end docking is improved , But sometimes configuration can drive people crazy , For example, the environment is configured with , But it never worked mvn、node Wait for the order . Execute... On the remote host shell But the project didn't start .

原网站

版权声明
本文为[Endwas]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020533117205.html