Jenkins2.32.3+Git+Maven+Tomcat+Ubuntu Linux

–>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
Jenkis Location
Jenkins URL, http://localhost:8080/jenkins or http://www.abc.abc/jenkins if the server had mapped to the domain.

Email Notification
Email Notification
User Name, your email account without suffix.
Use SSL, yes or it goes failure when deploying.
(Attention: your email should allow POP3 or IMAP.)

Publish Over SSH
Publish Over SSH
Remote Directory –> When Jenkins publish over SSH, it will upload WARs to [Remote Directory]. It must be set here or Jenkins could not find the directory on server. Examples like “/home/usr/jenkins_upload”.
(Attention:You can add more than one server at here, then you can choose them at the project configuration.)

(2)Global Tool Configuration
Maven Configuration
Maven Configuration
File path should be of the settings.xml currently in use.

JDK
JDK
JAVA_HOME, the path of java_home.

(3)Project Configure
Build Triggers
Build Triggers
Build whenever a SNAPSHOT dependency is built, YES.
Build periodically,
Schedule –>
15 11 * * * –> [minute] [hour] [day of month] [month] [day of week]
H 11 * * * –>H means a random range

Poll SCM
Schedule –>
*/2 * * * * –> Detect the gitlab every 2 minutes, if the SNAPSHOT have changed, Jenkins will re-publish the project.

Build
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).
Deploy war/ear to a container
WAR/EAR files–>figure out the war or ear files to deploy.
“**/*.war”, “**” means all directories in current jenkins project directory, “*.war” means all war(s) in each directory.
Context path–>The context path of the project on remote tomcat server. Jenkins need this path to visit the target project by web, so that jenkins will know if the project deploying finished.

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…)
Send build artifacts over SSH
Source files–>The war files that you want to upload.
Remove prefix–>remove the listed prefix of Source files.
Remote directory–>Rember the Remote directory of Publish Over SSH? Here means the subdirctory of Publish Over SSH’s Remote directory. Examples like “/project_name”.
Exec command –> A shell command or file.
Here I’ve created a shell file–>
(Attention: You must point out the java home in shell, because Jenkins doesn’t know the java home at remote server.)

#!/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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值