Jenkins构建自由风格项目发布jar到服务器

前面的文章有介绍 docker安装jenkins 和 docker+jenkins发布spring项目;这里就不做过多的介绍,直接说明构建步骤。

1、选择构建一个自由风格的项目 Jenkins构建自由风格项目发布jar到服务器_第1张图片

2、 选择丢弃旧的构建

Jenkins构建自由风格项目发布jar到服务器_第2张图片

 3、配置Git信息Jenkins构建自由风格项目发布jar到服务器_第3张图片

4、构建触发器 和 构建环境可以直接跳过

5、直接来到Build Steps这步骤,先新增一个调用顶层Maven目标配置编译项目(如果项目属于微服务架构,可添加多个调用顶层Maven目标步骤,先编译基础依赖包→在编译发布的项目)

Jenkins构建自由风格项目发布jar到服务器_第4张图片

6、在Build Steps这步骤,再添加一个 执行Shell

Jenkins构建自由风格项目发布jar到服务器_第5张图片

7、查看构建效果

Jenkins构建自由风格项目发布jar到服务器_第6张图片 附件脚本:

#!/bin/bash
echo "开始构建===============================>"
JenkinsHost=192.168.254.129
JenkinsPort=22
PROJECT_NAME='springboot-test'

ssh -p $JenkinsPort root@$JenkinsHost nohup pkill -15 -f $PROJECT_NAME.jar &
sleep 10s

echo "COPY JAR TO SERVER START===============================>"
ssh -p $JenkinsPort root@$JenkinsHost mkdir -p /work/project/$PROJECT_NAME
#scp -r /var/jenkins_home/workspace/fat2-springboot-test/target/$PROJECT_NAME.jar root@$JenkinsHost:/work/project/$PROJECT_NAME/
ssh -p $JenkinsPort root@$JenkinsHost /bin/cp -rf /work/docker/data/jenkins/workspace/fat2-springboot-test/target/$PROJECT_NAME.jar /work/project/$PROJECT_NAME/
echo "COPY JAR TO SERVER END===============================>"
echo "CHMOD START===============================>"
ssh -p $JenkinsPort root@$JenkinsHost chmod 755 /work/project/$PROJECT_NAME/$PROJECT_NAME.jar
echo "CHMOD START===============================>"

echo "SET LOGS START===============================>"
ssh -p $JenkinsPort root@$JenkinsHost mkdir -p /work/project/logs/$PROJECT_NAME
ssh -p $JenkinsPort root@$JenkinsHost touch  /work/project/logs/$PROJECT_NAME/$PROJECT_NAME.log
ssh -p $JenkinsPort root@$JenkinsHost chmod 777 /work/project/logs/$PROJECT_NAME/$PROJECT_NAME.log
echo "SET LOGS START===============================>"

echo "RUN JAR START===============================>"
ssh -p $JenkinsPort root@$JenkinsHost  << EOF
	nohup java -Xms256m -Xmx256m -Xmn256m -jar /work/project/$PROJECT_NAME/$PROJECT_NAME.jar > /work/project/logs/$PROJECT_NAME/$PROJECT_NAME.log 2>&1 &
EOF
echo "RUN JAR END===============================>"


你可能感兴趣的:(一体化运维部署学习,jenkins,运维,java,自动化部署jar)