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

9 comments:

  1. upon jetty start the shell script does'nt exit. what should i do?

    ReplyDelete
    Replies
    1. this line "nohup java -jar start.jar jetty.port=$JETTY_PORT > ../jetty.log 2>&1 &" is responsible for no hanging up jenkins job, can you post few last lines from jenkins output console job?

      Delete
    2. thnx for the reply..

      this is the last line from my console output.
      btw, I use hudson not jenkins.. haha.. tnks in advance.

      2013-12-16 09:59:50.093:INFO::Redirecting stderr/stdout to /export/home/exist/deployment/cohess_testing_3148/logs/2013_12_16.stderrout.log
      SSH: Disconnecting configuration [Developers] ...
      ERROR: Exception when publishing, exception message [Exec timed out or was interrupted after 120,001 ms]
      Finished: UNSTABLE

      and this is the log file from my server.

      DEBUG [main] StartupListener.contextInitialized(48) | Initializing context...
      DEBUG [main] StartupListener.contextInitialized(93) | Remember Me Enabled? null
      DEBUG [main] StartupListener.contextInitialized(95) | Password Encoder: ShaPasswordEncoder
      DEBUG [main] StartupListener.contextInitialized(97) | Populating drop-downs...
      INFO [main] StartupListener.initializeAppsConstants(111) | Constants Loaded from Database Successfully
      2013-12-16 10:00:24.224:INFO::started o.e.j.w.WebAppContext{/,file:/export/home/exist/deployment/cohess_testing_3148/work/webapp/},/export/home/exist/deployment/cohess_testing_3148/contexts/cohess-web-application/cohess-web-application.war
      DEBUG [main] LocaleFilter.init(172) | Initializing filter 'localeFilter'
      DEBUG [main] LocaleFilter.init(197) | Filter 'localeFilter' configured successfully
      2013-12-16 10:00:24.340:INFO:/:Initializing Spring FrameworkServlet 'dispatcher'
      2013-12-16 10:00:25.084:INFO::Started SelectChannelConnector@0.0.0.0:3148 STARTING

      Delete
    3. And I used different method for deploying.. First build, then execute the shell script after sending files over ssh.

      Delete
    4. Try to add "export" before defining BUILD_ID:
      export BUILD_ID=dontKillMe
      It looks like hudson/jenkins process killer is still killing your process after finishing job.

      Delete
    5. Now I'm getting unstable build because of the shell script continuing it's process, but if I wait for more than 2 mins and interrupt the build the web app seems to be deployed...

      Delete
  2. That maybe something hudson specific, but please drop a line if you manage to figure out how this should be done on hudson, thanks

    ReplyDelete
    Replies
    1. Sometimes bit stressless solution might be something like this (without the "export BUILD_ID.." and "BUILD_ID=..." lines)

      BUILD_ID=whatever nohup java -jar start.jar jetty.port=$JETTY_PORT > ../jetty.log 2>&1 &

      Should work the same for mr Hudson

      Regards,
      Lukas

      P.S. nice blog ;-)

      Delete
    2. I've applied your remark. Thanks.

      Delete