I want to share some Jenkins auto-deployment issue solutions, that I could not find on the internet including here.
But I'm almost a freshman in StackOverflow, so I'm just here to ask myself and answer myself right away.
// I have tried to share the solution public on GitHub issue, I could not use it well, too.
// asking to be excused...
I'm using Spring MVC 4.3.9, connected to CI/CD. // GitHub branch -> Jenkins -> TestServer (Tomcat 8.5)
I allowed all the IP addresses, made and set the right Tomcat Manager account both in Jenkins credentials menu and tomcat. But the same error always occurs -- TomcatManagerException and also the illegal argument exception (in the full log from Jenkins by maven build option, -X -e, not sure). // Same results, with both Deploy war plugin and SSH_publish plugin.
Here is the Jenkins console output. (I don't think this one is the full log.)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.895 s
[INFO] Finished at: ~~~Time~~~
[INFO] ------------------------------------------------------------------------
[DeployPublisher][INFO] Attempting to deploy 1 war file(s)
[DeployPublisher][INFO] Deploying ~~YourDIR&WAR~~ to container Tomcat 8.x Remote with context ~~YourContextName~~
Redeploying [ ~~YourDIR&WAR~~]
Undeploying ~~YourDIR&WAR~~]
Deploying [ ~~YourDIR&WAR~~]
ERROR: Build step failed with exception
org.codehaus.cargo.container.ContainerException: Failed to deploy [ ~~YourDIR&WAR~~]
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:104)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:180)
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:1075)
at hudson.FilePath.act(FilePath.java:1058)
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 hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
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:1905)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [~~YourContextName~~] but context failed to start
" 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.deployImpl(TomcatManager.java:767)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
... 19 more
org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The Tomcat Manager responded "FAIL - Deployed application at context path [~~YourContextName~~] but context failed to start
" 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.deployImpl(TomcatManager.java:767)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:312)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:99)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:180)
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:1075)
at hudson.FilePath.act(FilePath.java:1058)
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 hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:78)
at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:741)
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:1905)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:428)
Build step 'Deploy war/ear to a container' marked build as failure
Finished: FAILURE
* I also got illegal argument exception in maven console, in mapperLocations setting.
===> This is the key
This was my original mapper setting (causing the error). This setting just worked all fine when I run the Spring project on the local server. Also in the case that I exported war file on eclipse then deploy the war with my own hand to the server manually. Also in the case that I exported war file on eclipse then deploy the war with Tomcat Manager to the server manually.
** But only not available on Jenkins. Maven build was always successful but only in deployment. **
* Solution * => I have changed the mapper setting in the Spring project, and migrated mappers from
src/main/java
tosrc/main/resources
=> The cause of the error I have guessed is that Jenkins cannot read,<property name="mapperLocations" value="classpath:my/package/mapper/*.xml" />
, this configuration. => Same JDBC config, I only changed the mybatis setting like this.=> In
src/main/resources/mybatis-configuration.xml
=> Put the mybatis mappers in the directory,
src/main/resources/mapper
. Writeyourmapper.xml
like usual mybatis mapper XML file.P.S. -- I just have guessed that Jenkins cannot read the mappers in
src/main/java
. -- I haven't actually understood or analyze the open-source code of Jenkins. -- So the cause I pointed out might be wrong, but at least, the auto-deployment with Jenkins was available, in my mysterious case. -- I hope this might be helpful.