Continuous integration is a process that involves the build of the project but also the deployment of the artefacts (the term used with Maven). These artefacts are archives such as EAR, WAR, JAR files.
I had to write a shell script in Jenkins that would run just after the build and that would stop the JoNaS server, deploy the artefacts and restart JoNaS.
The project is based on Maven. However to create a job that executes a shell script, the first option “Build a free-style software project” seems best, instead of the “Build a maven2/3 project” option.
The process is quite simple :
1) stop JoNaS
2) delete the previous EAR file
3) copy the EAR file that was just built to the JoNaS deploy folder
4) restart JoNaS
I chose to poll the SCM every 10mn. So that means JoNaS checks every 10mn if a commit occured during the last 10mn. If so, it builds the project again. And deploys it.
Notice the highlighted line export BUILD_ID=dontKillMe. This is very important.
I spent about 2 hours wondering why JoNaS would start and then would stop after 20 or 30 seconds.
The reason is that Jenkins attempts to clean up after itself, so all processes that have that build ID are killed by default. So that processes do not accidentally leak and run the machine out of memory, for one.
The issue is described in this page with a funny title :
https://issues.jenkins-ci.org/browse/JENKINS-2729
Other interesting link :
http://wiki.hudson-ci.org/display/HUDSON/ProcessTreeKiller