5/28/2013

Deploy war on jetty in Jenkins or Hudson job


I don't want to say how many times I was writing combination of words: "Deploy jetty jenkins hudson job war" in Google search text field. I don't want to: use Cargo, use Jenkins/Hudson plugins, other automagick stuff that is working sometimes for specified conditions. My goal was to just deploy application war for testing purposes. if(Running) Done. I want this simple. I also want to deploy each application on separate port so I don't kill all applications when change code in one! Simple!

Build Environment :: Properties Content

JETTY_VERSION=8.1.11.v20130520
JETTY_PORT=9012

Build :: Execute Shell

# cleanup workspace
rm -rf *
# download jetty
wget http://download.eclipse.org/jetty/$JETTY_VERSION/dist/jetty-distribution-$JETTY_VERSION.tar.gz
tar xfz jetty-distribution-$JETTY_VERSION.tar.gz
mv jetty-distribution-$JETTY_VERSION jetty
rm jetty-distribution-$JETTY_VERSION.tar.gz

Build :: Copy artifacts from another project

Project name: <jenkins build name where war artifact is stored>
Artifacts to copy: **/*.war
Target directory: jetty/webapps

Build :: Execute Shell

# kill jetty if running
pkill -9 -f jetty.port=$JETTY_PORT || true
sleep 5
cd jetty
start jetty & prevent jenkins killing job after finish
BUILD_ID=dontKillMe nohup java -jar start.jar jetty.port=$JETTY_PORT > ../jetty.log 2>&1 &

Done!

You know how to do this simpler? Drop a line.

Edit 1: As Łukasz pointed out, it's good idea to combine two last lines (prevent & run) into single one