Jenkins部署项目到Tomcat8,项目名为ROOT出现问题

小小魔炎 发布于 2017/06/30 16:17
阅读 1K+
收藏 2

最近引入了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)部署经验的大牛指点

加载中
0
小小魔炎
小小魔炎

不要沉啊,求大神解救

0
铂金蛋蛋
铂金蛋蛋
你要实现热部署?
0
铂金蛋蛋
铂金蛋蛋
#BUILD_ID=DONT_KILL_ME
sudo kill -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").war
sh /opt/tomcat/bin/shutdown.sh
cp /var/lib/jenkins/workspace/项目/target/ROOT.war /opt/tomcat/webapps/ROOT.war
sh /opt/tomcat/bin/startup.sh

在 Run only if build succeeds 里使用

0
小小魔炎
小小魔炎

引用来自“铂金蛋蛋”的评论

#BUILD_ID=DONT_KILL_ME
sudo kill -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").war
sh /opt/tomcat/bin/shutdown.sh
cp /var/lib/jenkins/workspace/项目/target/ROOT.war /opt/tomcat/webapps/ROOT.war
sh /opt/tomcat/bin/startup.sh

在 Run only if build succeeds 里使用

感谢大牛的命令,不过我也尝试用远程执行命令行暂时解决了

但还是很好奇,tomcat是不是对ROOT项目有保护机制,不允许通过账户名密码部署的方式覆盖ROOT

返回顶部
顶部