Jenkins+svn+maven+tomcat One-click Build deployment

Source: Internet
Author: User
Tags relative svn svn client ssh iptables tomcat tomcat server

1 Background
This is a multi-person collaborative development, automatic construction, automatic deployment of the scenario. You do not have to pack your own, and then upload the deployment, liberation of manpower, easy to manage. This is a simple introduction to the use and integration of their software, in fact, no matter svn and Maven have a lot of practical usage, SVN management planning, MAVEN warehouse and so on.
SVN is used for code versioning, maven for compiling, Tomcat as a web container, and Jenkins as a tool for automated builds. Here does not use Nginx to do direction agent, later do
Software version
jdk1.8
tomcat8-deploying Jenkins, Port 8080
tomcat7-Deploying an App Web project, Port 8090
jenkins2.46
maven3.5

2 Installing Jenkins
2.1 Installing the JDK
Download, unzip, rename, modify the configuration file, and finally use java-version verification, very simple. But more descriptive.

2.2 Installing TOMCAT8
Download, unzip, rename the website

2.3 Installing Jenkins
Then put the Jenkins war into Tomcat's WebApp (/home/tomcat8/webapps) and start Tomcat
/home/tomcat8/bin/startup.sh

2.4 Modify firewall, open 8080 port
Vim/etc/sysconfig/iptables
-A input-m state–state new-m tcp-p tcp–dport 8080-j ACCEPT
Restart Firewall service iptables restart
Access URL
http://192.168.247.141:8080/jenkins/

Here, follow his instructions for password verification.
More/root/.jenkins/secrets/initialadminpassword

Install the plugin below

Select the plugin and install the recommended bar
Then wait a long time, then enter the user name and password
Here wangqi,wangqi,444687196@qq.com
After the plug-in installation is complete


2.5 Install plugins yourself
Install SSH Slaves plugin (run the shell command), MAVEN integration Plugin (build MAVEN project),
Deploy to Container Plugin (deploying the app Web).
In Jenkins ' System Management-plug-in management-optional plugins can be selected

3 Installing SVN
3.1 Check if SVN has been installed
Rpm-qa Subversion
If it is already installed, remove the Yum remove Subversion

3.2yum Installation
Yum Install Subversion
Mkdir/home/svn/game
Svnadmin Create/home/svn/game
Cd/home/svn/game
ll

The Conf directory is a configuration file, and the DB directory is the code that places each version (encrypted)
3.3 Planning SVN and configuring SVN
Planning:
Planning Group: Open planning, art reading and writing
Back-end group: read-write on the back-end, plan-only
Front End group: read-write, planning, art reading
Art Group: Open Art reading and writing, planning read-only
Administrators group: all read and write

Permissions Configuration
Vim/home/svn/game/conf/authz
The meaning of RW is to read and write

[Game:/server]
@server =RW
This means that the server user can have read and write access to the server directory under the more SVN game

[Groups]
#管理组
Manager = Boss
#服务端用户组
server = server1,server2
#客户端用户组
client = Client1,client2
#美术组
art = Art1,art2
#策划组
design=design1,design2
[game:/]
@manager =rw
[Game:/server]
@server =RW
[Game:/client]
@client =rw
@design =r
@art =r
[Game:/art]
@design =rw
@art =rw
@client =r
[game :/design]
@design =rw
@server =r
@client =r
@art =r

Modify User Password
vim/home/svn/game/conf/passwd

[Users]
boss=123456
server1=123456
server2=123456
client1=123456
client2=123456
art1=123456
art2=123456
design1=123456
design2=123456

Modify SVN service
Vim/home/svn/game/conf/svnserve.conf

auth-access = Write
anon-access = read
password-db = passwd
authz-db = Authz
Realm =game

Firewall Development SVN Port
Vim/etc/sysconfig/iptables
-A input-m state–state new-m tcp-p tcp–dport 3690-j ACCEPT

Service Iptables Restart

3.4 Start SVN service
Svnserve-d-r/home/svn/
-D: Daemon
-R:SVN root directory
Suppose the server-side IP is 192.168.247.141, then the Access directory for the game is as follows:
Svn://192.168.247.141/game

The SVN client uses the Turtle (Tortoise SVN installation directly next), looking for a directory checkout, if successful SVN installs successfully.

4 Installing Maven
Download from http://maven.apache.org/

Unzip, rename
TAR-ZXVF apache-maven-3.5.0-bin.tar.gz
RM-RF apache-maven-3.5.0-bin.tar.gz
MV apache-maven-3.5.0/maven3.5

Configuring Environment variables
Vim/etc/profile

m2_home=/home/maven3.5
path= $PATH: $JAVA _home/bin: $JRE _home/bin: $M 2_home/bin

Modify MAVEN's configuration, vim settings.xml

<localRepository>/home/maven3.5/jar</localRepository>

Then copy your maven jar into the jar, or it will be re-downloaded.
The basic software is ready.

5 Spring Tool suit
I wrote the code using spring tools suit, where the SVN plugin was installed by Help-install.
Right-click Project-temp-shareproject-Select SVN
Then fill in the SVN connection, account, password, you can upload it. Install the prompt step-by-step to go.



After uploading SVN successfully, the project will appear as a link to the diagram, stating that the code has been managed by SVN.

6 Building a deployment web App with Jenkins
6.2 Create a new job
Choose the free style here, project name Nsfw-server

Then configure the job
6.2 Configuring the Job's SVN

To configure SVN, pay special attention to the SVN path, you need to specify to the project name ha
Using SVN's boss user, the boss user has read and write access to all directories

6.3 Build Plan
Every 8 o'clock in the evening, the time to change their own ha, configuration and crontab the same way

6.4 Build Environment
Here need to source/etc/profile first, or you can not use the MVN command (I do this here), where the SSH (need to install the SSH plugin ha), need in the system configuration

6.5 How to build
Build mode choose Invoke top-level MAVEN targets.
Goals is the MAVEN command, setting is the MAVEN configuration path

Clean install means to delete the previously compiled target and recompile the build war

6.6 Automatic deployment to the Web container

The war path is the relative path to the workspace directory relative to Jenkins
My full path:/root/.jenkins/workspace/nsfw-server/nsfw-server/target/nsfw-server.war
/represents the WebApps directory that will replace the Crm.adminWeb.war with Root.war and put it into Tomcat.
/nsfw-server, not in the root directory, just under WebApp.
Tomcat's information is primarily user name and password (from Tomcat-users.xml).
Jenkins seems to support TOMCAT7 deployment.
Here is a TOMCAT7 installation, where a tomcat-userx.xml is mainly configured.

<role rolename= "Manager-gui"/>

<user username= "Wangqi" password= "Wangqi" roles= "Manager-gui"/>

With this Wangqi user, you can execute a deployment command.

The job configuration is complete

6.7 Performing the Build
To perform a build manually

The following small dot, you can see the execution of the log.

As can be seen from the log, the war package has been MVN compiled, and then deployed to the Tomcat server, and finally finished:success.

See if the Tomcat deployment is complete

Visit Http://192.168.247.141:8090/nsfw-server/pic/upIndex, success

Automation builds successfully.

PS:
1 if mvv-s * Clean install, can run on the machine, but Jenkins cannot run, then must be the problem of environment variables, use before building using Source/etc/profile
2 If you modify the SVN code, after uploading, it may be unsuccessful to execute the build immediately, because the SVN version is not synchronized and will be available for a few minutes later.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.