How to deploy a war file in GlassFish 4 server Using Jenkins

how to deploy war file in glassfish server
how to start glassfish server

I am using Jenkins to deploy a war file in GlassFish 4 server.But unable to deploy war file in Glassfish 4 server. I am following below process.

But it gives following error at the build time.

ERROR: Build step failed with exception org.codehaus.cargo.util.CargoException: Cannot create the DeploymentManager at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.getDeploymentManager(AbstractJsr88Deployer.java:356) at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.redeploy(AbstractJsr88Deployer.java:192) at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:77) at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:147) at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:117) at hudson.FilePath.act(FilePath.java:1047) at hudson.FilePath.act(FilePath.java:1025) at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:114) at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeploy(PasswordProtectedAdapterCargo.java:93) at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:64) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690) at hudson.model.Build$BuildExecution.post2(Build.java:186) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635) at hudson.model.Run.execute(Run.java:1819) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Caused by: javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException: Could not get DeploymentManager; No registered DeploymentFactory handles this URI at javax.enterprise.deploy.shared.factories.DeploymentFactoryManager.getDeploymentManager(DeploymentFactoryManager.java:117) at org.codehaus.cargo.container.glassfish.GlassFish3xRemoteDeployer.getDeploymentManager(GlassFish3xRemoteDeployer.java:82) at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.getDeploymentManager(AbstractJsr88Deployer.java:352) ... 18 more javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException: Could not get DeploymentManager; No registered DeploymentFactory handles this URI at javax.enterprise.deploy.shared.factories.DeploymentFactoryManager.getDeploymentManager(DeploymentFactoryManager.java:117) at org.codehaus.cargo.container.glassfish.GlassFish3xRemoteDeployer.getDeploymentManager(GlassFish3xRemoteDeployer.java:82) at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.getDeploymentManager(AbstractJsr88Deployer.java:352) at org.codehaus.cargo.container.spi.deployer.AbstractJsr88Deployer.redeploy(AbstractJsr88Deployer.java:192) at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:77) at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:147) at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:117) at hudson.FilePath.act(FilePath.java:1047) at hudson.FilePath.act(FilePath.java:1025) at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:114) at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeploy(PasswordProtectedAdapterCargo.java:93) at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:64) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:690) at hudson.model.Build$BuildExecution.post2(Build.java:186) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:635) at hudson.model.Run.execute(Run.java:1819) at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Build step 'Deploy war/ear to a container' marked build as failure Finished: FAILURE

I was able to delopy to glassfish 4 using any one method from following two methods:

  1. Method 1 Using new version of Deploy to container Plugin

    You can clone following from github (Note: you can try with new version of plugin)

    https://github.com/jenkinsci/deploy-plugin/tree/205715c3556ade8d8665de677ebb41e35ee64793

    Now build the project and in target folder you can find deploy.hpi file which can be install in jenkins. This version has support for Glassfish 4.

    To install plugin manually: How to install a plugin in Jenkins manually

  2. Method 2 Add following in jenkins as execute shell.Update the value as required and create glassfish password file.It will undelpoy the ear file and deploy the new one.

#!/bin/bash

# FOR JENKINS

# Update following values as required
GLASSFISH_PASSWORD_FILE_PATH=/home/pwd

ASADMIN_PATH="/home/glassfish4/glassfish/bin/asadmin"
ASADMIN_BASE_CMD="$ASADMIN_PATH --host 10.13.209.100 --port 9048 --user admin2 --passwordfile $GLASSFISH_PASSWORD_FILE_PATH"

DEPLOY_EAR_FILE_PATH="Dummy-project-ear/target"
DEPLOY_EAR_FILE_NAME="Dummy-project-ear-1.0-SNAPSHOT.ear"

UNDEPLOY_EAR_NAME="Dummy-project-ear-1.0-SNAPSHOT"

# Commands

$ASADMIN_BASE_CMD list-applications
$ASADMIN_BASE_CMD undeploy $UNDEPLOY_EAR_NAME
$ASADMIN_BASE_CMD deploy $DEPLOY_EAR_FILE_PATH/$DEPLOY_EAR_FILE_NAME

is to ensure that the entire process which is shown above is automated. I'm trying to deploy the war to remote Glassfish 4.1 server using Jenkins (V2.138.1) deploy to container plugin(v1.13) with following configuration WAR/EAR files : target/myapp.war Context path : /

Change the Glassfish hostname to 127.0.0.1 or localhost it's work for me!

Next, change to the Files tab. Open the 'build.xml' file, as shown below. Also, for later reference, note the contents of the 'HelloGlassFish.war' and  The test target depends on other targets to build the .war file. If you are not using test to execute unit tests, you can call the test target to build the .war file. The last part of the ‘jenkins-glassfish-deploy’ target is a little different.

Example using Windows batchfile

@ECHO OFF 
:: BAT START GLASSFISH 5 SERVER
ECHO ============================
ECHO STOPING GLASSFISH 5
ECHO ============================
tasklist | find /i "java.exe" && taskkill /im java.exe /F || echo process "java.exe" not running.
ECHO ============================
ECHO NETWORK INFO
ECHO ============================
ipconfig | findstr IPv4
ECHO ============================
ECHO STARTING GLASSFISH 5
ECHO ============================
ECHO Please wait...
ping 127.0.0.1 -n 10 > nul
net start domain1
ECHO Please wait... Restarting Server
ping 127.0.0.1 -n 90 > nul
exit  0

Running The batchfile:

asadmin --echo=true --host=localhost --port=4848 --user=admin --passwordfile=C:\FilePassGF\passwordfile.txt --secure=false deploy --name "NameWar" --contextroot "NameWar" --force=true "C:\Jenkinshome\deploys\$JOB_NAME\$BUILD_NUMBER\Target-1.0.war"

To install Jenkins on Glassfish, simply copy jenkins.war to Jenkins by overwriting $GLASSFISH_HOME/domains/domain1/autodeploy/jenkins.war with a newer version. Again Glassfish needs to be restarted for this change to take effect. Files and images; Link; Markup; Horizontal rule; Task list; Date; Emoticon; Symbol. Undeploying a war file To undeploy NewDemoService.war file you need to use the following command. Note that here you don't have to use the full name but literal "NewDemoService".

Open up a terminal, change directory to the GlassFish installation directory and run following. But GUI lovers, for any consolation I have put some screenshots which you can follow if you prefer the Use the following command to deploy your war file. Using Jenkins and Java for Continuous Integration. Step 1: Add to Tomcat a user with deployment rights. For a successful Jenkins Tomcat deploy of a WAR file, you must add a new user to Tomcat with manager-script rights. You can do this with an edit of the tomcat-users.xml file, which can be found in Tomcat's conf directory. <!--.

PierceCollegeDist11 Recommended for you SQLite: The Database at the Edge of the Duration: 9:20 Posted: Sep 12, 2014 Step 2 − Go to your Build project and click the Configure option. Choose the option “Deploy war/ear to a container”. Step 3 − In the Deploy war/ear to a container section, enter the required details of the server on which the files need to be deployed and click on the Save button.

Jenkins - Automated Deployment - There are many plugins available which can be used to transfer the build files To use this follow the steps given below. This plugin takes a war/ear file and deploys that to a running remote application server at the end of a build. Tomcat 4.x/5.x/6.x/7.x. JBoss 3.x/4.x. Glassfish 2.x/3.x. How to run Jenkins on Docker container | How to create Jenkins Volumes on Docker | Beginners - Duration: 16:41. Automation Step by Step - Raghav Pal 118,137 views 16:41

Comments
  • You want to deply to glassfish 3 (in Jenkins config) or 4 (like your tag says)?
  • Thank you Jens for response my question. I want to deploy in GlassFish 4, here ip and port number belongs to GlassFish 4. But in jenkines no option for GlassFish 4.
  • @BimalKumarDalei are you using Deploy to container Plugin?
  • Yes @MukeshM, i am using Deploy to container plugin.
  • @BimalKumarDalei i try with new version of plugin and it worked for me.But for new version you have to clone and build Deploy to container Plugin project from github.