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 project
2) Configure source code management, pull code from gitlab
3) Compile and package
Build -> Add build step -> Executor Shell
echo "$(date) 开始编译和打包"
mvn clean package
echo "$(date) 编译和打包结束"
Build and test now
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 #停止
However, 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
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" />
-->
3) Configure tomcat, just visit the browser
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.
2) Add Tomcat user credentials
3) Add post-build operations
4) Click "Build Now" to start the build process
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!