步骤:
1、打开jenkins客户端,登录;
2、点击左侧菜单栏【新建任务】,输入任务名称,点选自由风格的软件项目,点击【确定】;
3、写关于当前任务的描述
4、源码管理中填写项目的git地址,登录账号,代码所在分支
5、构建触发器不用勾选,构建环境中勾选如下图:
6、构建
1)增加构建步骤,选择 执行shell
命令框中输入:
source /etc/profile //刷新环境变量配置
mvn clean package //打包
sh 服务对应.sh文件的路径.sh .sls文件名称 服务器Ip地址
7、保存、应用
8、到jenkins所在服务器上配置.sh和.sls文件
- 注意:.sh文件和.sls文件的文件名需要和git上项目名一致
.sls文件
.sh文件
#!/bin/sh source /etc/profile SHELLPATH="/data/shell/" SALTPATH="/app/salt/base/init/" JENKINS_FILE="/app/salt/base/jenkins/files/" WORKSPACE="/data/data/jenkins/.jenkins/workspace/" PRO_NAME=$1 REMOTE_IP=$2 TARGET=`ls ${WORKSPACE} | grep ${PRO_NAME} | grep -v ‘@tmp‘ | grep TEST` PACKAGE_NAME=`/usr/bin/ls ${WORKSPACE}${TARGET}/target/ | grep ‘jar‘ | grep -v ‘original‘` /usr/bin/cp ${WORKSPACE}${TARGET}/target/${PACKAGE_NAME} ${JENKINS_FILE} /usr/bin/cp ${SHELLPATH}salt_template.sls ${SHELLPATH}${PRO_NAME}.sls /usr/bin/sed -i "s/PRO_NAME/${PRO_NAME}/g" ${SHELLPATH}${PRO_NAME}.sls /usr/bin/sed -i "s/PACKAGE_NAME/${PACKAGE_NAME}/g" ${SHELLPATH}${PRO_NAME}.sls /usr/bin/cp ${SHELLPATH}${PRO_NAME}.sls ${SALTPATH} /usr/bin/salt ${REMOTE_IP} cmd.run "pkill -f ${PRO_NAME}" /usr/bin/salt ${REMOTE_IP} state.sls init.${PRO_NAME} /usr/bin/salt ${REMOTE_IP} cmd.run "echo ‘source /etc/profile && nohup java -jar ${PACKAGE_NAME} > /dev/null 2>&1 &‘ > /app/java/${PRO_NAME}.sh" /usr/bin/salt ${REMOTE_IP} cmd.run "cd /app/java && nohup /usr/bin/sh ${PRO_NAME}.sh > /dev/null 2>&1 &"
9、构建任务,并到控制台查看日志是否显示构建成功
原文地址:https://www.cnblogs.com/hd-test/p/11302291.html
时间: 2024-10-06 16:39:53