how does jenkins undeploy and deploy war to tomcat works? - maven

Im wondering how does Jenkins undeploy and deploy a war into a Tomcat container. I have a job which builds and deploy the created war to a tomcat server and i cant understand how Jenkins does the undeploy.
**
IMPORTANT: ExampleName.war and ExampleName#test-1234.war are the SAME project, but built with different pom version naming conventions**
If i deploy a war named ExampleName.war in Tomcat andm later i build-deploy via jenkins the same war with the same name, it automatically detects it.. so Jenkins goes for a Undeploy -> Deploy war into the server.
Now here's my question: if the war already deployed is ExampleName.war and then i build and deploy via jenkins a war named ExampleName#test-1234.war , the job fails. How does Jenkins and Tomcat communicate to detect if a war is already deployed, so in case does the undeploy-deploy?
Is the check made by war name? If so, actually the war name is different so it should skip the undeploy?
Here the error i get from Jenkins in the 2nd case (war name obscured):
Discard old builds...
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying ExampleName#test-1234.war to container Tomcat 7.x Remote with context null
**Redeploying ExampleName#test-1234.war]**
** Undeploying [ExampleName#test-1234.war]**
**ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to undeploy [ExampleName#test-1234.war]**
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.undeploy(AbstractTomcatManagerDeployer.java:132)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:165)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
at hudson.FilePath.act(FilePath.java:1200)
at hudson.FilePath.act(FilePath.java:1183)
at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:79)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:765)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:709)
at hudson.model.Run.execute(Run.java:1922)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)
**Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - No context exists for path /ExampleName#test-1234.war**
**" instead of the expected "OK" message**
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:501)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.undeploy(TomcatManager.java:441)
at org.codehaus.cargo.container.tomcat.Tomcat7xRemoteDeployer.performUndeploy(Tomcat7xRemoteDeployer.java:58)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.undeploy(AbstractTomcatManagerDeployer.java:122)
... 20 more
**org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - No context exists for path /ExampleName#test-1234.war**
**" instead of the expected "OK" message**
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:721)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:501)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.undeploy(TomcatManager.java:441)
at org.codehaus.cargo.container.tomcat.Tomcat7xRemoteDeployer.performUndeploy(Tomcat7xRemoteDeployer.java:58)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.undeploy(AbstractTomcatManagerDeployer.java:122)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:165)
at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:81)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:167)
at hudson.plugins.deploy.CargoContainerAdapter$DeployCallable.invoke(CargoContainerAdapter.java:136)
at hudson.FilePath.act(FilePath.java:1200)
at hudson.FilePath.act(FilePath.java:1183)
at hudson.plugins.deploy.CargoContainerAdapter.redeployFile(CargoContainerAdapter.java:133)
at hudson.plugins.deploy.PasswordProtectedAdapterCargo.redeployFile(PasswordProtectedAdapterCargo.java:95)
at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:113)
at jenkins.tasks.SimpleBuildStep.perform(SimpleBuildStep.java:123)
at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:79)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:816)
at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:765)
at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072)
at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:709)
at hudson.model.Run.execute(Run.java:1922)
at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543)
at hudson.model.ResourceController.execute(ResourceController.java:101)
at hudson.model.Executor.run(Executor.java:442)
**Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE**
Jenkins tries to undeploy ExampleName#test-1234.war even if the war previously deployed is ExampleName.war.
Which is ok, i mean i want to "override" ExampleName.war with ExampleName#test-1234.war ... but i guess he doesnt know what to undeploy if not specified (or if war name isnt exactly the same?)
Thank you very much

Related

Problem in deploying to IBM bluemix java/spring service

I am deploying a java spring boot application as a deployable war into an IBM bluemix environment via jenkins. I am able to build and run the service in my local environment. During the build pipeline, I am getting this. Any ideas?
Staging app and tracing logs...
Downloading liberty-for-java...
Downloaded liberty-for-java
Cell 26776ec2-6370-4ef1-8987-54aa61d8fe79 creating container for instance 1cc919a5-8e81-4c91-aa64-9b7274d7715d
Cell 26776ec2-6370-4ef1-8987-54aa61d8fe79 successfully created container for instance 1cc919a5-8e81-4c91-aa64-9b7274d7715d
Downloading app package...
Downloaded app package (2.6K)
-----> Liberty Buildpack Version: v3.44-20200430-1451
E, [2021-02-22T22:06:45.730075 #22] ERROR -- /tmp/buildpacks/fb2e823ce09e8909e2afd757be3d1971/lib/liberty_buildpack/buildpack.rb:50:in `rescue in drive_buildpack_with_logger': Compile failed with exception #<RuntimeError: No supported application type was detected>
No supported application type was detected
Failed to compile droplet: Failed to compile droplet: exit status 1
Exit status 223
Cell 26776ec2-6370-4ef1-8987-54aa61d8fe79 stopping instance 1cc919a5-8e81-4c91-aa64-9b7274d7715d
Cell 26776ec2-6370-4ef1-8987-54aa61d8fe79 destroying container for instance 1cc919a5-8e81-4c91-aa64-9b7274d7715d
Error staging application: App staging failed in the buildpack compile phase
FAILED
The error basically means the buildpack did not find an artifact it recognizes as an app it supports. The liberty buildpack recognizes wars, jars, liberty server directories and packaged servers.
The buildpack will look for an artifact in the current directory or in the directory specified with the -p CLI flag or path in the manifest.
Ensure your artifact exists where the buildpack can find it.

Jenkins Deployment Issue

I'm using Jenkins to deploy war file into tomcat.Build is success but giving FileNotFound exception.I'm using tomcat7.I found some references in google but didn't get the solution
if you want to copy war from build server to tomacat server ,use robocopy to copy war to tomcat server
robocopy c:abc/abc.war //tomcatserver and path
Most containers have a directory where you can "place" the war, in order to deploy it.
Therefore in Jenkins you can set up Send build artifacts over SSH
More
On configuring the server, you should go in Configure Jenkins -> Configure system -> SSH Servers
Add the server you need to deploy to, username (+password) and Remote directory: /opt/app/tomcat/webapps (or whatever)
More info here - https://wiki.jenkins.io/display/JENKINS/Publish+Over+SSH+Plugin

404 when deploying Grails 3.1.10 war to tomcat7 or tomcat8

The closest stackoverflow question that explains my symptoms is here - How can I deploy a Grails 3.0.1 war file in Tomcat7?
I am in the process of upgrading a Grails 2.3.4 application to Grails 3.1.10 and everything is working with 'grails run-app'.
When i deploy to a war i get nothing but 404's for any url.
The war deploys without any error messages in catalina.out.
The tomcat access logs show my access attempts. (not linux problem?)
I can get to the tomcat manager, and the tomcat manager shows my app as "running" as true. (no errors)
Manager shows myapp-0.1 because the war file was myapp-0.1.war .. this is fine for now.
I am running Grails 3.1.10.
I have tried against Tomcat 7.0.55 as well as 8.0.92.
I have tried changing grails.serverUrl in application.groovy to various values. It is now:
//fix war name after get working
grails.serverUrl = "/myapp-0.1"
System.setProperty("server.contextPath","/myapp-0.1")
I have tried the above without "-0.1". (i was suprised to learn this was necessary - https://stackoverflow.com/a/23664531/104993)
I have tried changing "org.springframework.boo:spring-boot-starter-tomcat" from "compile" to "provided" in the build.gradle file.
Please let me know what I need to elaborate on. It's difficult to paste log outputs and config files. (i'm behind a firewall)
You add the following task to your build.gradle it will name the war what ever you want:
task wrapper(type:Wrapper){
war.archiveName='myWar.war'
}
Then when you deploy it should have the correct name and you can go to https://localhost:8080/myWar

Team City: Cannot Redeploy to Tomcat7

I have a build configuration that uses the Team City deployer plugin.
I'm using a container deploy to deploy the war file to Tomcat.7.0.63 installed as a service on a Windows Server 2012 R2 box.
The first time I run the the build, the artifact (a war file_ deploys successfully.
The second time, and all subsequent runs, the deploy fails.
The error message:
Build failure message received: org.codehaus.cargo.container.ContainerException: Failed to undeploy
The log file error:
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: FAIL - Unable to delete
When I go to the webapps folder on the remote server, the war file is deleted, but the expanded folder is only partially deleted. Most files are gone, except for a png file.
I am not able to manually delete the folder because Tomcat still has a lock on it.
If I restart tomcat, I'm then able to run the build successfully (war file deploys).
One thought I had was to restart Tomcat before or after each deploy.
How would I restart Tomcat from TeamCity?
Or perhaps, does anyone have suggestions on how to fix this problem?
You can configure the Tomcat Context using the antiResourceLocking option, as detailed further in the online documentation. This does come with some trade-offs however; definitely worth reading the documentation in full and evaluating if it's a suitable option for your application.

TOMCAT 7 not deploying war

I have developed a Dynamic Java Project with Eclipse which involves web services(RESTful). After completion I tried to run my project Tomcat 7 runtime of Eclipse IDE, it works fine. I am able to access all my web services.
But, when I created a WAR file out of my project by right-clicking on project and exporting it to WAR file and placed .war file in Tomcat 7's webapps folder. Started the tomcat by running startup.bat, it throws below exceptions and I am not able t access any web service:
I have placed all the required jar files in lib folder of Tomcat.
Exception fixing docBase for context [/Books] (Books is my war file name)
Failed to create work directory [{CATALINA_HOME}\work\Catalina\localhost\Books]
Failed to create destination directory to copy resources.
Could anyone please let me know what I am missing??
Thanks in advance.
Regards,
Piyush
The failed to create "work directory" error can occur if the work folder does not exist in the tomcat7 folder.
Also this error can be caused by tomcat not having sufficient permissions to read, write and execute in the tomcat7 directory.
The issue is because, tomcat is not finding your web.xml location in the classpath.
Do below steps:
Right click on web project-->Properties-->Deployment Assembly--> Add your classpath to web.xml(src/main/webapp) in my case.

Resources