Continuous integration environment (three)-Jenkins build free style project

1 Introduction to Jenkins project build types

There are many types of automatic construction projects in Jenkins, and the following three are commonly used:

  • FreeStyle Project (FreeStyle Project)
  • Maven Project
  • Pipeline Project

Each type of construction can actually complete the same construction process and results, but it is different in terms of operation mode, flexibility, etc. You can choose according to your own needs and habits in actual development. (PS: Personally recommend to use the pipeline type, because the flexibility is very high)

2 Free style project construction

The following demonstrates the creation of a free style project to complete the integration process of the project:

拉取代码->编译->打包->部署

2.1 Pull code

1) Create a projectInsert picture description here

2) Configure source code management, pull code from gitlabInsert picture description here

3) Compile and package

Build -> Add build step -> Executor Shell

echo "$(date) 开始编译和打包" 
mvn clean package 
echo "$(date) 编译和打包结束"

Build and test now
Insert picture description here

2.2 Installation and configuration of tomcat

1) Install Tomcat8.5

Upload the Tomcat compressed package to the 10.99.200.110 server (/root/pkg/)

cd /root/pkg/
tar -xf apache-tomcat-9.0.33.tar.gz   #解压
cd apache-tomcat-9.0.33
./bin/startup.sh          #启动
./bin/shutdown.sh         #停止

Insert picture description hereInsert picture description hereHowever, the subsequent Jenkins deployment project to the Tomcat server requires a Tomcat user, so modify the following configuration of tomcat, add users and permissions.

2) Configure tomcat

1> Modify the tomcat-users.xml file of tomcat

cat conf/tomcat-users.xml

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
    <role rolename="tomcat"/> 
    <role rolename="role1"/> 
    <role rolename="manager-script"/> 
    <role rolename="manager-gui"/> 
    <role rolename="manager-status"/> 
    <role rolename="admin-gui"/>
    <role rolename="admin-script"/>
    <user username="tomcat" password="tomcat" roles="manager-gui,manager-script,tomcat,admin-gui,admin-script"/> \
</tomcat-users>

User and password are: tomcat
Insert picture description here

2> Modify the context.xml file under the tomcat manager

Purpose: In order to enable the user just configured to log in to Tomcat, the following configuration needs to be modified

vim webapps/manager/META-INF/context.xml

<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" 
            allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> 
-->

Insert picture description here

3) Configure tomcat, just visit the browser

Insert picture description here
Insert picture description here

2.3 Deployment (deploy the project to the remote Tomcat)

Prerequisite: When it comes to the database, create the database and tables in advance, and configure the database account and password used.

1) Install the Deploy to container plug-in

Purpose: Jenkins itself cannot realize the function of remote deployment to Tomcat, it needs to install the Deploy to container plug-in.
Insert picture description here

2) Add Tomcat user credentials

Insert picture description here

3) Add post-build operations

Insert picture description here

4) Click "Build Now" to start the build process

Insert picture description here
Insert picture description here
Up to this step, it has been proved that the deployment was successful. As for the picture is not displayed, it is because I have not adjusted the configuration.

It's all here. For more articles, please refer to the personal WeChat public account ALL In Linux, let's scan it!
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44729138/article/details/115097002