最近引入了Jenkins自动化部署,前面拉代码、打包都没问题,唯独部署出问题。
为了访问方便(能从根目录访问网站),我们是将项目打包为ROOT.war丢到tomcat的webapps下的。
已经配置好了tomcat的相关用户deploy并给予了权限。
这里是我们的测试服务器以远程部署的方式给自己部署,也就是输入了自己的网址和端口号。
经测试,如果项目名字不是ROOT.war(比如起名abc.war),经过Jenkins构建并通过Deploy to container Plugin插件部署后,再次构建是可以覆盖前面的abc.war
但ROOT.war不能被覆盖,如果webapps下面有ROOT.war,直接构建部署会报错Error writing request body to server:
Deploying /srv/codes/eshifu_boss/target/ROOT.war to container Tomcat 7.x Remote [/srv/codes/eshifu_boss/target/ROOT.war] is not deployed. Doing a fresh deployment. Deploying [/srv/codes/eshifu_boss/target/ROOT.war] ERROR: Build step failed with exception org.codehaus.cargo.container.ContainerException: Failed to deploy [/srv/codes/eshifu_boss/target/ROOT.war] at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:111) at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:185) at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73) at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116) at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103) at hudson.FilePath.act(FilePath.java:997) at hudson.FilePath.act(FilePath.java:975) at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103) at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:676) at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:621) at hudson.model.Run.execute(Run.java:1760) at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:542) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:405) Caused by: java.io.IOException: Error writing request body to server at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(HttpURLConnection.java:3479) at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3462) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.pipe(TomcatManager.java:647) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:538) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:611) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:291) at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:102) ... 17 more java.io.IOException: Error writing request body to server at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(HttpURLConnection.java:3479) at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3462) at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82) at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.pipe(TomcatManager.java:647) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:538) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deployImpl(TomcatManager.java:611) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.deploy(TomcatManager.java:291) at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.deploy(AbstractTomcatManagerDeployer.java:102) at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:185) at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:73) at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:116) at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:103) at hudson.FilePath.act(FilePath.java:997) at hudson.FilePath.act(FilePath.java:975) at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:103) at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:61) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:735) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:676) at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:621) at hudson.model.Run.execute(Run.java:1760) at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:542) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:405) Build step 'Deploy war/ear to a container' marked build as failure Finished: FAILURE
目前解决方案是:写一个本地脚本,在部署前将原有的ROOT.war和解压后的ROOT文件夹删掉,这样才能顺利部署。
因为后期打算用测试服务器以远程部署到线上服务器,可这样就没办法通过执行本地脚本清空原有项目,这个疑问还是要解决的。
恳求有Jenkins+Tomcat(+Git+Maven)部署经验的大牛指点
不要沉啊,求大神解救
你要实现热部署?#BUILD_ID=DONT_KILL_MEsudokill-9`netstat-tlnp|grep端口|awk'{print$7}'|awk-F'/''{print$1}'` cp/opt/tomcat/webapps/ROOT.war/opt/backwar/washcar_$(date-d"today"+"%Y%m%d_%H%M%S").warsh/opt/tomcat/bin/shutdown.shcp/var/lib/jenkins/workspace/项目/target/ROOT.war/opt/tomcat/webapps/ROOT.warsh/opt/tomcat/bin/startup.sh
在 Runonlyifbuildsucceeds里使用
#BUILD_ID=DONT_KILL_MEsudokill-9`netstat-tlnp|grep端口|awk'{print$7}'|awk-F'/''{print$1}'` cp/opt/tomcat/webapps/ROOT.war/opt/backwar/washcar_$(date-d"today"+"%Y%m%d_%H%M%S").warsh/opt/tomcat/bin/shutdown.shcp/var/lib/jenkins/workspace/项目/target/ROOT.war/opt/tomcat/webapps/ROOT.warsh/opt/tomcat/bin/startup.sh
在 Runonlyifbuildsucceeds里使用
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。