Simple deployment

If you installed your Jenkins CI on the same host as the Glassfish server, this is easy. You just have to let maven do its thing and then add this shell command:

/usr/local/glassfish/bin/asadmin --echo=true --host=localhost --port=4848 --user=admin --passwordfile=/secure/place/for/passwords/domain1_password --secure=false deploy --force=true --name=myproject --contextroot=/myproject target/*.war

The /secure/place/for/passwords/domain1_password file should contain this:

AS_ADMIN_PASSWORD=the_password

Deploying different versions

With parametrized builds, you can go a little further and decide, for instance, if you want to deploy the current version as the production one or not. You can switch the build as a parametrized one and add a “stable” parameter (with a default value of false), for example.

The the only thing you have to do is to switch the previous code to:

if $stable; then
    /usr/local/glassfish/bin/asadmin --echo=true --host=localhost --port=4848 --user=admin --passwordfile=/secure/place/for/passwords/domain1_password --secure=false deploy --force=true --name=myproject --contextroot=/myproject target/*.war
else
    /usr/local/glassfish/bin/asadmin --echo=true --host=localhost --port=4848 --user=admin --passwordfile=/secure/place/for/passwords/domain1_password --secure=false deploy --force=true --name=myproject-test --contextroot=/myproject-test target/*.war
fi

Using the jabber plugin

Then you can use the jabber plugin, and you can discuss with your Jenkins build system. It’ll look something like that:

!build myproject

And when you feel you are ready to go live:

!build myproject stable=true

Notes

  • You can reproduce this with other servers, like tomcat or jetty.
  • Glassfish is considered to be quite heavy. Like most of the OSGi-based software, you can remove the components you don’t need.