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 to build Jenkins + Git + Maven + tomcat + nexus integrated environment

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

How to build Jenkins + Git + Maven + tomcat + nexus integrated environment, I believe that many inexperienced people do not know what to do. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Implement "automatically build and deploy" web applications

1. Installation environment

Operating system: Centos 7.2

JDK:1.8.x

Maven:3.5.x

Git: 1.8.1, self-built GitLab platform

Tomcat:8.x

two。 Third-party installation installation and environment configuration

Add hosts parsing

JDK, Git, Maven, and tomcat need to be installed on both host machines, that is, both jenkins master and slave need these environments.

1) JDK installation: slightly; after installation, please pay attention to configuring the JAVA_HOME environment variable.

2) Maven installation: download the tar.gz package from apache and decompress it in the appropriate directory. The M2_HOME environment variable is then configured.

If you use the Maven central warehouse nexus of private server, specify / usr/server/apache-maven-3.5.0/conf/settings.xml

3) tomcat installation: slightly.

4) Git: the installation is very simple, just execute "yum install git" directly.

5) if your GitLab is a self-built private network platform, don't forget to add hosts resolution to the above two host machines, for example:

Install a tomcat with http port 8082

Download the war package of jenkins and put it in http://mirrors.jenkins-ci.org/war/ under tomcat

1) context.xml: add the jenkins environment variable, which is mounted by tomcat.

"JENKINS_HOME" is the home directory of jenkins, which is usually set to a partition with "large disk space". This directory will place maven build files, historical deployment records, and so on, so it will consume a lot of storage space.

"cacheMaxSize" specifies the memory unit K, which is added if insufficient memory is reported.

2) tomcat-users.xml: users who configure jenkins, after which users can log in and authorize operations on the jenkins page. For jenkins user authorization, there are many official ways, such as LDAP, database-based, and so on. This example is based on tomcat user and is easy to use.

Add 2 administrator users, of which admin can modify the configuration of the system, and manager can manage the project, deployment, and so on.

3) place jenkins.war in the webapps directory, and here we want jenkins to be loaded as a ROOT project, so delete the original ROOT project and rename jenkins.war to ROOT.war, so that when accessing jenkins through http, there is no need to add ContextPath.

4) start jenkins tomcat:./startup.sh

5) visit "http://192.168.1.194:8082", and then log in using the admin user (see tomcat-users.xml for the user password).

1. User rights configuration

System Management-- > Configure Global Security

Security domain: Jenkins proprietary database

Search strategy: login users can do anything

2.mail configuration

System Administration-- > system configuration-- > Jenkins Location

Fill in the system administrator address

System Administration-- > system configuration-- > email Notification

SMTP Server smtp.126.com

User default mail suffix @ 126.com

Use SMTP authentication

User name system_mail_ul@126.com

Password

3.jdk, git, maven configuration

System Management-- > Global Tool Configuration

Add jdk, git, maven paths

/ usr/server/jdk1.7.0_80

/ usr/server/apache-maven-3.5.0

4.Build and release

We next create a job that downloads the source code locally from GitLab, then uses Maven build and packaging, and publishes it to tomcat. This process is exactly what we often use.

Please install the Deploy to container plugin plug-in first; it is mainly used to put the "war" file "deploy/redeploy" into the web container, such as tomcat, jboss, and so on. With this plug-in, we can publish war to tomcat immediately after maven build, without having to manually or write the shell script copy file.

First, we need to prepare a tomcat to deploy our web application, with a slight process. This tomcat has port 8080 and is deployed on the master host machine.

Because the Deploy plug-in is "deploy/redeploy" in an external (http) way, user authorization needs to be done on tomcat. Edit the tomcat-users.xml and add the following configuration:

By adding a "deployer" user, we can deploy war through the tomcat manager mechanism. See the explanation later.

Triggers are not actually needed.

Here's what my test looks like.

Finally, configure the tomcat container path, and you are done. Please note

TomcatA8 is an administrative user here, and you need to have manager-gui,manager-script,manager-jmx,manager-status permission, otherwise an error will be reported.

If you use nginx proxy, you need to set the maximum buffer size greater than the war packet size, otherwise an error will be reported.

The error message can be viewed under the Console Output menu in the build task.

There are two ways to pack a positive ROOT.war:

1. Change the name in the pom.xml file to the name you want

two。 Context path: / ROOT in the settings above

The "WAR/EAR files" option specifies the location of the war, which is a relative path. Relative to "/ home/jenkins_home/workspace/ {your item name}", this example is a maven multi-module project, and the name of each module package is ROOT.war, which is convenient for deployment. Ask the administrator to specify the correct path.

In Containers, we use tomcat 7, enter the user name and password we set above, and specify tomcat Url. It is important to note that since the application is deploy based on http manager, the "manager" project included in the webapps of this tomcat cannot be deleted, and the tomcat also needs to be started. (tomcat may also be considered dead, so it is recommended to add a judgment on the status of tomcat in pre step, and if tomcat dies, execute startup.sh first.)

If an error is reported during deployment. Please check as follows:

1) whether tomcat has been started.

2) whether the tomcat-users.xml is configured correctly.

3) whether the version of tomcat is consistent with that specified by container in "Deploy plugin".

4) whether there is already a ROOT project under tomcat. If so, delete and restart tomcat, and then publish it using jenkins, because reploy will check the version compatibility of the old ROOT and the new ROOT.war project, and if different, it will cause reploy to fail.

Build log:

[JENKINS] Archiving / u01/jenkins_home/workspace/gkgp/web/pom.xml to com.tudou.gkgp/web/1.0-SNAPSHOT/web-1.0-SNAPSHOT.pom [JENKINS] Archiving / u01/jenkins_home/workspace/gkgp/web/target/gkgp.war to com.tudou.gkgp/web/1.0-SNAPSHOT/web-1.0-SNAPSHOT.war [gkgp] $/ bin/sh-xe / home/jenkins/apache-tomcat-8.0.36/temp/hudson7572047694542790795.shchannel StoppedDeploying / u01/jenkins_home/workspace/gkgp/web/target/gkgp.war to container Tomcat 8.x Remote with context / gkgp [/ u01/jenkins_home/workspace/gkgp/web/target/gkgp.war] is not deployed. Doing a fresh deployment. Deploying [/ u01/jenkins_home/workspace/gkgp/web/target/gkgp.war] Finished: SUCCESS

-END

Other: profile

The values of each attribute node are placed with the placeholder "${attribute name}". When maven is in compile/package, it automatically replaces these placeholders to the actual attribute values according to the environment of the profile.

By default:

Maven package

The default active profile environment will be used for packaging, or you can specify the environment manually, such as:

Maven package-P dev

Will be automatically packaged into a deployment package for the dev environment (note: parameter P is uppercase)

Realize "automatic build and deploy" web application to realize "automatic construction and deployment" of web application

After reading the above, have you mastered how to build a Jenkins + Git + Maven + tomcat + nexus integrated environment? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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

Servers

Wechat

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

12
Report