Jenkins continuous deployment of gitee-based projects
Jenkins actual combat requires the server to install the following software
- Jenkins
reference https://blog.csdn.net/m0_50217781/article/details/112417128 - git
reference https://blog.csdn.net/m0_50217781/article/details/112398132 - maven
reference https://blog.csdn.net/m0_50217781/article/details/112400740 - tomcat
reference https://blog.csdn.net/fukai8350/article/details/80467224
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
Then modify our default file address
/home/deploy/repository/
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
After the startup is complete, the browser opens Jenkins
http://ipaddress:port
See this familiar old man, enter the account password to log in
Then click New Item,
enter the task name, select the free item,
and define two String variables, one is the file name, the other is the url
Note that the url here is the project url in our jitee
Get it here.
After you finish, you can start writing and executing scripts.
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
Wait for the build to complete, you can
also check the deployment