企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
一、Jenkins介绍 ![](https://upload-images.jianshu.io/upload_images/5432753-66f40cb252c5b559.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 二、Jenkins的下载安装 1、下载地址:[https://jenkins.io/download/](https://jenkins.io/download/)(下载速度极慢),下载Jenkins的war直接丢进tomcat的webapps目录即可完成部署。 2、.将war包丢进服务器的tomcat/webapps目录,或者执行nohup   java  -jar  jenkins.war & 浏览器访问:127.0.0.1:8080/jenkins 3、第一次安装启动  需要解锁。 ![](https://upload-images.jianshu.io/upload_images/5432753-721975ee8bdc4d6f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/5432753-bb76940587b32f77.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 4、推荐插件安装  巨慢 ![](https://upload-images.jianshu.io/upload_images/5432753-835683b7ad2dcb88.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 5.创建用户 ![](https://upload-images.jianshu.io/upload_images/5432753-e40d879a582e29d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 6、实例配置 ![](https://upload-images.jianshu.io/upload_images/5432753-beaf6a225e8de3b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 7、开始使用 ![](https://upload-images.jianshu.io/upload_images/5432753-e89d23ef0594386a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 至此、Jenkins的下载安装,完成,下面对Jenkins进行一系列的配置。 三、Jenkins配置 1、插件安装 选择插件管理=》可选插件搜索即可安装插件 ①\*\*Maven Integration:\*\*新建job时有maven项目可以选择; ②\*\*Deploy to container:\*\*将war包部署到tomcat所在的服务器上; ③\*\*Publish Over SSH:\*\*通过ssh推送文件,并可以执行shell命令; \* 2.Maven、Git、JDK配置\* 点击:“系统管理”------>“全局工具配置” ![](https://upload-images.jianshu.io/upload_images/5432753-c7c231d2c4aa03c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/5432753-8d4276f886dce625.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 四、项目打包、发布、运行 1、新建任务 ![](https://upload-images.jianshu.io/upload_images/5432753-f69d3480677f896c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) 2、配置任务 准备:1、远程代码仓库 例如:[https://gitee.com/haijun0314/test.git](https://gitee.com/haijun0314/test.git) 2、远程服务器执行脚本   /usr/hjmall/apps/start.sh 脚本内容: ``` #!/bin/sh source ~/.bash_profile source /etc/profile export JAVA_HOME=/usr/java/jdk1.8.0_211 export JRE_HOME=$JAVA_HOME/jre export test=hj-test-1.0.jar export test_port=9000 case "$1" in start) ##test echo "--------test  starting--------------" nohup java -jar $test >/dev/null 2>&1 & test_pid=lsof -i:$test\_port|grep "LISTEN"|awk '{print $2}' until [ -n "$test_pid" ] do test_pid=lsof -i:$test\_port|grep "LISTEN"|awk '{print $2}' done echo "test pid is $test_pid" echo "--------test  started-------------" echo "===startAll success===" ;; stop) P_ID=ps -ef | grep -w $test | grep -v "grep" | awk '{print $2}' if [ "$P_ID" == "" ]; then echo "===test process not exists or stop success" else kill -9 $P_ID echo "test killed success" fi echo "===stopAll success===" ;; restart) $0 stop sleep 2 $0 start echo "===restartAll success===" ;; esac exit 0 ``` ![](https://upload-images.jianshu.io/upload_images/5432753-c61a5a72056ce7b4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/5432753-2b124594b5cabc03.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240) ![](https://upload-images.jianshu.io/upload_images/5432753-2a338bcd19222ef0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)