Jenkins部署完项目后,执行服务器上脚本重启Tomcat

该前提是在服务器目录/root下已存有重启Tomcat的脚本restart.sh。
在Jenkins上依此进入到配置—-构建环境,然后选中“Execute shell script on remote host using ssh”,如下:
这里写图片描述
然后在SSH site中填入目标机器的信息,或是选择在配置中已配置的机器;
Pre build script中填入构建前要执行的脚本;
Post build script中填入构建后要执行的脚本。该记录是为了在Jenkins构建后执行重启Tomcat的操作,所以填入此处:

#!/bin/bash -ilex
source /etc/profile   #此处也可放入restart.sh文件中
sh ~/restart.sh

点击保存后即可直接用Jenkins部署项目,且重启Tomcat,不用手动启动。

发布了46 篇原创文章 · 获赞 13 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/luliuliu1234/article/details/80932751