Jenkins continuous deployment of gitee-based projects in linux actual combat

Jenkins continuous deployment of gitee-based projects

Jenkins actual combat requires the server to install the following software

Start actual combat

First add in our linux maven configuration file

<!-- 阿里云仓库-->
<mirror>
  <id>alimaven</id>
  <mirrorOf>central</mirrorOf>
  <name>aliyun maven</name>
  <url>https://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

First check the mvn installation path, and then edit the setting.xml file in the conf directory
Insert picture description here

Insert picture description here

Then modify our default file address

/home/deploy/repository/

Insert picture description here

OK pre-deployment is complete, we start to configure Jenkins

Specify the port to start Jenkins, do not use 8080, or it will conflict with tomcat

java -jar /usr/lib/jenkins/jenkins.war --httpPort=8088

Insert picture description here
After the startup is complete, the browser opens Jenkins

http://ipaddress:port

Insert picture description here

See this familiar old man, enter the account password to log in

Then click New Item,
Insert picture description here
enter the task name, select the free item,
Insert picture description here
and define two String variables, one is the file name, the other is the url

Insert picture description here
Insert picture description here

Insert picture description here
Note that the url here is the project url in our jitee

Get it here.
Insert picture description here
Insert picture description here
After you finish, you can start writing and executing scripts.

Insert picture description here

Insert picture description here
note Jenkins will use processTreeKiller to kill all child processes after the build is complete, and this is the default behavior of Jenkins.

#!/bin/bash
#解决jenkins杀死衍生进程

export BUILD_ID=dontkillme

echo "=======进入的git仓库目录======="
mkdir -p /developer/git-rep/deploy/
cd /developer/git-rep/deploy/
#echo "=======删除之前克隆的目录======"
rm -rf /developer/git-rep/deploy/$git_dir
#echo "=======git克隆项目======="
git clone $git_url

cd /developer/git-rep/deploy/$git_dir

echo "=========更新git仓库最新代码到本地========="
git fetch


echo "========git pull========="
git pull



echo "=========maven打包项目========="
mvn clean package -Dmaven.test.skip=true


echo "=========删除tomcat中旧的ROOT.war========="
rm -rf /apps/tomcat/webapps/ROOT.war




echo "=========拷贝最新的war到tomcat中========="
cp /developer/git-rep/deploy/$git_dir/target/nd.com.war /apps/tomcat/webapps/ROOT.war



echo "=========删除旧的ROOT文件夹========="
rm -rf /apps/tomcat/webapps/ROOT



echo "=========关闭tomcat========="
sh /apps/tomcat/bin/shutdown.sh

echo "=========休眠10秒========="
for i in {
    
    1..10}
do
        echo ${
    
    i}"s"
        sleep 1s

done

echo "=========启动tomcat========="

sh /apps/tomcat/bin/startup.sh -Dspring.profiles.active=$profile


echo "重新部署完成!!"

Please modify the specific related parameters according to your own configuration

After the configuration is complete, you can start building

Insert picture description here
Wait for the build to complete, you can
Insert picture description here
also check the deployment

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_50217781/article/details/112430843