–>Wed Mar 22 2017 –>Jenkins_2.32.3 –>Jenkins plugins: Maven Integration plugin, Publish Over SSH, Deploy to Container Plugin (These plugins you have to install manually!) –>Tomcat9 –>Ubuntu_16.04 Server
Jenkins is a simple tool to deploy WARs automatically. With several plugins and a few simple configurations, Jenkins can deploy projects on a local pc or publish local projects to remote sites. You can see installation steps in other blogs. For 2.32.3, some options during the confiurations may lead to failures and here just take a note for how to configure these options.
(1) Configure System Jenkins Location
Email Notification
Publish Over SSH
(2)Global Tool Configuration Maven Configuration
JDK
(3)Project Configure Build Triggers
Poll SCM Schedule –> /2 * * * * –> Detect the gitlab every 2 minutes, if the SNAPSHOT have changed, Jenkins will re-publish the project.
Build
Post-build Actions (1) Deploy war/ear to a container Jenkins is installed on PC-A(local), and now you are going to deploy a project to Tomcat on PC-A(local).
Send build artifacts over SSH Jenkins is installed on PC-A(local), and now you are going to use Jenkins to publish a project to Tomcat on a remote server PC-B(remote). (Attention: You can add more than one remote servers here, PC-C, PC-D, PC-E…)
#!/bin/bash
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_121
while getopts "r:t:p:" arg
do
case $arg in
r)
remote_dir=${OPTARG}
;;
t)
tomcat_home=${OPTARG}
;;
p)
project_name=${OPTARG}
;;
?)
exit 1
;;
esac
done
echo "${remote_dir} ${tomcat_home} ${project_name}"
tomcat_pid=`/usr/bin/lsof -n -P -t -i :8080`
if [ -n "${tomcat_pid}" ];then
echo "if"
kill -9 ${tomcat_pid}
sleep 1
fi
rm -rf ${tomcat_dir}/webapps/${project_name}*
cp ${remote_dir}/${project_name}/*.war ${tomcat_home}/webapps/
${tomcat_home}/bin/startup.sh