首页 > 其他分享> > 用Jenkins部署war包到tomcat8报错"ERROR: Build step failed with exception org.codehaus.cargo.container.C
用Jenkins部署war包到tomcat8报错"ERROR: Build step failed with exception org.codehaus.cargo.container.C
作者:互联网
一、 Jenkins部署war包到tomcat8
1. 构建结果FAILURE
查看Jenkins控制台,输出的报错的信息如下:
[JENKINS] Archiving /var/lib/jenkins/workspace/java-demo/target/demo-0.0.1-SNAPSHOT.war to com.example/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.war channel stopped [java-demo] $ /bin/sh -xe /tmp/jenkins4892978097067932620.sh + pwd /var/lib/jenkins/workspace/java-demo [DeployPublisher][INFO] Attempting to deploy 1 war file(s) [DeployPublisher][INFO] Deploying /var/lib/jenkins/workspace/java-demo/target/demo-0.0.1-SNAPSHOT.war to container Tomcat 8.x Remote with context /java_demo ERROR: Build step failed with exception org.codehaus.cargo.container.ContainerException: Failed to redeploy [/var/lib/jenkins/workspace/java-demo/target/demo-0.0.1-SNAPSHOT.war] at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:176) 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:1171) at hudson.FilePath.act(FilePath.java:1154) 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:78) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:806) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:755) at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:699) at hudson.model.Run.execute(Run.java:1913) at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543) at hudson.model.ResourceController.execute(ResourceController.java:99) at hudson.model.Executor.run(Executor.java:432) Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:710) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:882) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:895) at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:161) ... 19 more Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://120.78.226.139:8080/manager/text/list at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1914) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1512) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:577) ... 22 more org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:710) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:882) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:895) at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:161) 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:1171) at hudson.FilePath.act(FilePath.java:1154) 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:78) at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:47) at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:806) at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:755) at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.post2(MavenModuleSetBuild.java:1072) at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:699) at hudson.model.Run.execute(Run.java:1913) at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:543) at hudson.model.ResourceController.execute(ResourceController.java:99) at hudson.model.Executor.run(Executor.java:432) Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://120.78.226.139:8080/manager/text/list at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1914) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1512) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:577) ... 22 more Build step 'Deploy war/ear to a container' marked build as failure Finished: FAILURE
二、 解决办法:
1. 修改tomcat-users.xml文件
编辑tomcat安装目录下的tomcat-users.xml文件,添加用户和权限
[root@Jessiestart conf]# vi /usr/local/tomcat/apache-tomcat-8.5.73/conf/tomcat-users.xml
在最后添加如下内容
注意:要在<tomcat-users> </tomcat-users>内
<role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager-gui"/> <role rolename="admin-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="tomcat" roles="manager-gui,tomcat,admin-gui,manager-script"/>
现在用户名和密码都是:tomcat,等下配置Jenkins需要用到
2. 修改context.xml配置
打开context.xml文件
[root@Jessiestart META-INF]# vi /usr/local/tomcat/apache-tomcat-8.5.73/webapps/manager/META-INF/context.xml
然后注释掉这部分
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
三、 重启tomcat
1. 先停止,再启动tomcat
[root@Jessiestart bin]# /usr/local/tomcat/apache-tomcat-8.5.73/bin/shutdown.sh
[root@Jessiestart bin]# /usr/local/tomcat/apache-tomcat-8.5.73/bin/startup.sh
2. 输入URL访问tomcat
在浏览器输入http://ip:port/manager/html
然后输入用户名tomcat,密码tomcat
成功访问
四、 配置Jenkins
1. 在"构建后操作"中,添加刚才设置的tomcat用户名和密码
用户名:tomcat
密码:tomcat
五、验证
1. 再次构建项目
构建结果:SUCCESS
2. 打开浏览器,输入URL地址进行查看
可以正常访问了。
搞定!
标签:cargo,exception,java,tomcat,hudson,报错,TomcatManager,container,CargoContainerAdap 来源: https://www.cnblogs.com/littlemonsterksn/p/15873415.html