2 gitlab + jenkins maven automatically update package

Introduction environment: Based on the first article codes automatically updates the environment, jenkins gitlab not installed, the first one with reference to

jenkins need to install Maven Integration plugin plugin

wget http://updates.jenkins-ci.org/download/plugins/maven-plugin/3.4/maven-plugin.hpi

Need to be installed on a web interface to upload after downloading

jenkins Configuration

1, a new maven task, discard the old building of 7 days

 

 

2, add gitlab on the project and address verification mode, select the branch build.

 

 3. Select the trigger type, here I choose to build when gitlab updates. And generates a secret token in the senior years.

 

 4, built pom build file path and command parameters to build into the war when the successful implementation of the corresponding automated update script command

 

 

#!/bin/bash

CODE_DIR = " / var / lib / Jenkins / Workspace / carespay / target / "      # project directory
DATE_TIME = ` DATE + M-%%% Y-H-D-%%% M- S '# Time Format
DIR_NAME=carespay-${DATE_TIME}
TAR_NAME = after the package name $ DIR_NAME.war #
WEB_ADDR=192.168.10.227                   #web服务器地址
WEB_DIR="/usr/local/tomcat5/webapps"             #web服务器站点目录的上一级 "/usr/local/tomcat1/webapps"
WEB_NEWDIR_NAME=web-${DATE_TIME}        #web服务器新建的站点目录名字

#进入到项目目录并打包代码
tarcf_code(){
    cd $CODE_DIR && mv carespay-ms.war /opt/$TAR_NAME
}

#拷贝到web服务器的站点目录的上一级
scp_code(){
    scp /opt/$TAR_NAME $WEB_ADDR:$WEB_DIR
}

#连接web服务器备份旧版代码
tarxf_code(){
    ssh $WEB_ADDR "cd $WEB_DIR && mv carespay*  ../back/ "
}

#将新建的站点目录与html站点目录做一个软链接
ln_code(){
    ssh $WEB_ADDR "cd $WEB_DIR && rm -rf new && ln -s $DIR_NAME new"
}

#重启tomcat
reboot(){
    ssh $WEB_ADDR "cd $WEB_DIR && sh reboot.sh && sleep 1m"
}

#删除旧代码
del_code(){
    ssh $WEB_ADDR "cd $WEB_DIR && rm -rf $TAR_NAME"
}


main(){
    tarcf_code;
    tarxf_code;
    scp_code;
    reboot;
    ln_code;
}
main
自动化代码更新脚本
#!bin/bash
#手动重启tomcat5

tid=$(ps -ef |grep tomcat5 |grep -v grep |awk  '{print $2}')

kill -9 $tid

sh /usr/local/tomcat5/bin/startup.sh

echo `date`  $tid "tomcat5 已重启" >>../reboot.log
192.168.10.227 tomcat重启脚本

gitlab设置

1、创建一个真实项目,从git克隆真实代码过来。

2、项目--设置---集成,添加jenkins项目地址和token成为一个绑定的Webhooks。

 

 3、gitlab上用webide模拟一下更新代码,查看jenkins构建状态和10.227tomcat是否构建成功。

 

 

 

 

 

 

 

可以看到成功自动构建,其中还有很多需要优化的地方,如有更好的建议,欢迎大家留言~~~

 

4、如果有报jdbc这类jar包无法下载错误,直接拷贝一个jar到相应的目录,因为这类jar无法自动下载成功

[root@xfg 11.2.0.3]#ls
ojdbc6-11.2.0.3.jar  ojdbc6-11.2.0.3.jar.lastUpdated  ojdbc6-11.2.0.3.pom.lastUpdated
[root@xfg 11.2.0.3]#pwd
/root/.m2/repository/com/oracle/ojdbc6/11.2.0.3

Guess you like

Origin www.cnblogs.com/xiefugui/p/12084617.html
Recommended