What I really love about Jenkins is his straightforward approach, when you do things with it. A short installation, a fast first configuration and a lot of good plugins, which can do a lot for you.
So I had also a look to the “Deploy to container Plugin”. It looked tempting, because I have an enterprise application which I want to deploy into an Application Server (GlassFish) after a success build.
First try first error. The plugin alert with
ERROR: Publisher hudson.plugins.deploy.DeployPublisher aborted due to exception
org.codehaus.cargo.util.CargoException: Deployment has failed: Action failed Deploying application to target server failed; File not found : /var/lib/jenkins/jobs/shop/workspace/shop-ear/target/shop-ear-1.0-SNAPSHOT.ear
at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.waitForProgressObject(AbstractJsr88Deployer.java:220)
at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.deploy(AbstractJsr88Deployer.java:76)
at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.redeploy(AbstractJsr88Deployer.java:142)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:60)
at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:86)
at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:73)
at hudson.FilePath.act(FilePath.java:785)
at hudson.FilePath.act(FilePath.java:767)
at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:73)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:45)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:694)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:669)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.post2(MavenModuleSetBuild.java:978)
at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:616)
at hudson.model.Run.run(Run.java:1429)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:470)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:230)
Finished: FAILURE
After a while of search, try and error I found the problem. My Application Server has not enough permission to access the ear file which is created by the jenkins user. After I include the glassfish user to the same group as the jenkins user it works – yeah!
I was happy and proceed with my work.
But then when I did a new commit on the scm system and jenkins try to build the project new, it couldn’t deploy it again. The build was a success ([INFO] BUILD SUCCESS), but the the deployment plugin alert with:
Deploying /var/lib/jenkins/jobs/shop/workspace/shop-ear/target/shop-ear-1.0-SNAPSHOT.ear to container GlassFish 3.x Remote
ERROR: Publisher hudson.plugins.deploy.DeployPublisher aborted due to exception
org.codehaus.cargo.util.CargoException: Deployment has failed: Action failed Deploying application to target server failed; Error occurred during deployment: Application with name shop-ear-1.0-SNAPSHOT is already registered. Either specify that redeployment must be forced, or redeploy the application. Or if this is a new deployment, pick a different name. Please see server.log for more details.
at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.waitForProgressObject(AbstractJsr88Deployer.java:220)
at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.deploy(AbstractJsr88Deployer.java:76)
at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.redeploy(AbstractJsr88Deployer.java:142)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:60)
at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:86)
at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:73)
at hudson.FilePath.act(FilePath.java:785)
at hudson.FilePath.act(FilePath.java:767)
at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:73)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:45)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:36)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:694)
at hudson.model.AbstractBuild$AbstractRunner.performAllBuildSteps(AbstractBuild.java:669)
at hudson.maven.MavenModuleSetBuild$RunnerImpl.post2(MavenModuleSetBuild.java:978)
at hudson.model.AbstractBuild$AbstractRunner.post(AbstractBuild.java:616)
at hudson.model.Run.run(Run.java:1429)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:470)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:230)
Now the message was a bit more precisely. I have to force the deployment. In the console I can easily add the parameter “--force” to my asadmin deployment command, but the plugin doesn’t allow this option to me. So what can I do?
My not so well solution, add a “Hudson Post build task” which undeploy the current application from the server. In detail I add a condition which search the “Log text” for the following regex pattern “target/(.+).ear“.
If match is found (means, that the ear file was created) it execute the following script
/PATH/TO/THE/ASADMIN/COMMAND/asadmin undeploy $(basename $(find -name "*.ear") .ear)
Explanation:
$(find -name "*.ear") – looks for a file (inclusiv path) with the extension ear
$basename – strip directory and suffix from filenames
So, the script execution looks like:
/PATH/TO/THE/ASADMIN/COMMAND/asadmin undeploy shop-ear-1.0-SNAPSHOT.ear
After that, I can now deploy the application each time, when a build success. So a success story? Not at all!
When I rethink my solution, why do I deploy my Application not at all with the post build task and skip the deployment plugin…