centOS7 build jenkins, achieve maven + tomcat + vue remote server build automation

In the project development process, developers need to deploy daily update test environment, if the project is distributed, published a number of projects to build, it requires a large time cost. So here consider building jenkins to automate building.

Jenkins first introduced here centOS build process:

1, the installation jdk1.8, install a variety of ways not described in detail, as an example of this with yum

yum  install  java-1.8.0-openjdk
vi /etc/profile

JAVA_HOME=/usr/lib/jvm/java
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH

2, the installation package installation jenkins 

wget http://pkg.jenkins-ci.org/redhat-stable/jenkins-2.7.3-1.1.noarch.rpm
rpm -ivh jenkins-2.7.3-1.1.noarch.rpm

3, start jenkins

service jenkins start

4, jenkins initial configuration, the new user

 

5, with the new administrator account, log jenkins

 So far jenkins has been completed structures. Below you start configuring the back-end engineering automation building:

1, system management - global tool to configure the new global configuration section

Configuration setting file, JDK, Git installation directory

Configuring Maven installation directory and NodeJS (vue building need to use)

 --- System Management Plug-In Manager to install Maven plug-ins and Node

2, a new job, building a maven project

 

3, configuration items related note: there are many pit (where version control tools to gitlab for example)

A first address and configuration gitlab accounts linux attention needs to switch to jenkins user , go to SSHKEY gitlab generated, and then copy the gitlab, not described in detail here, if the user does not switch jenkins, where the source will not be connected!

Here explain some input

username is jenkins, passphrase for the ssh password, key to git private , in the following figure, jenkins is private, jenkins.pub for the public

(PS: If you do not know which card will be a long time)

Second, the configuration file relative path pom

Third, after compiling a remote server configured address and account number

Fourth, the configuration file and send remote service after sending operations

 

Fifth, writing shell scripts in remote server / app / jenkins / script

#!/bin/bash
export BUILD_ID=dontKillMe

echo "stop app tomcat..."
pid_service=`ps -ef|grep tomcat-app-service-8090|grep -v "grep"|awk '{print $2}'`
kill -9 $pid_service
echo "KILL $pid_service:"
pid_web=`ps -ef|grep tomcat-app-web-8091|grep -v "grep"|awk '{print $2}'`
kill -9 $pid_web
echo "KILL $pid_web:"
cd /app/poseidon/tomcat-app-service-8090/webapps
rm -rf app-service
rm -rf app-service.war
cp /app/jenkins/app-service.war ../webapps/
cd ../bin/
./startup.sh
 
cd /app/poseidon/tomcat-app-web-8091/webapps
rm -rf app-web
rm -rf app-web.war
cp /app/jenkins/app-web.war ../webapps/
cd ../bin/
sleep 30
./startup.sh

cd /app/jenkins/
rm -rf app-service.war
rm -rf app-web.war

       If you are familiar with the above script shell script, it should be easy to understand, do not know their next Baidu 

       Probably a simple process flow is first stopped tomcat, tomcat deleted at war package, copied from jenkins directory, and then restart the tomcat

Sixth, save the configuration, run the project 

Seven, you can view the output log in Console Output

Eight, success was successfully constructed

 

Vue front-end engineering automation building under the following brief 

First, the other configuration is basically the same, you can refer to the above, you need to configure node plug

Second, write a script compiler

echo $PATH
node -v
npm -v
cd ls-dedao
npm install chromedriver --chromedriver_cdnurl=http://cdn.npm.taobao.org/dist/chromedriver
npm install
npm run build
cd /var/lib/jenkins/workspace/dist/app_h5
npm install
npm run build
cp -r /var/lib/jenkins/workspace/dist/app_h5/dist /var/lib/jenkins/workspace/dist/ls-dedao/dist
cd /var/lib/jenkins/workspace/dist/ls-dedao/dist
mv dist app
cd ../
rm -rf html
rm -rf html.tar.gz
mv dist html 
tar zcvf html.tar.gz html

Third, the remote server after a successful compilation send 

Fourth, the remote server to write shell scripts 

#!/bin/bash
export BUILD_ID=dontKillMe

cd /app/poseidon/
rm -rf html
tar -xvf html.tar.gz
sleep 3
rm -rf html.tar.gz

 

Fifth, compared with the same success success

 

So far maven + tomcat + vue remote server automation project has been constructed, the timing can be designed to build time in the configuration. 

Here jenkins docker is not recommended to be installed, and the path is relatively environment-related problems, more pit. 

Published 41 original articles · won praise 47 · views 30000 +

Guess you like

Origin blog.csdn.net/u014526891/article/details/85075037